@@ -10,7 +10,8 @@ import 'package:gsy_github_app_flutter/widget/gsy_card_item.dart';
1010
1111typedef void SelectItemChanged <int >(int value);
1212
13- class GSYSelectItemWidget extends StatefulWidget implements PreferredSizeWidget {
13+ class GSYSelectItemWidget extends StatefulWidget
14+ implements PreferredSizeWidget {
1415 final List <String > itemNames;
1516
1617 final SelectItemChanged selectItemChanged;
@@ -47,25 +48,34 @@ class _GSYSelectItemWidgetState extends State<GSYSelectItemWidget> {
4748 _GSYSelectItemWidgetState ();
4849
4950 _renderItem (String name, int index) {
50- var style = index == selectIndex ? GSYConstant .middleTextWhite : GSYConstant .middleSubLightText;
51+ var style = index == selectIndex
52+ ? GSYConstant .middleTextWhite
53+ : GSYConstant .middleSubLightText;
5154 return new Expanded (
52- child: RawMaterialButton (
53- materialTapTargetSize: MaterialTapTargetSize .shrinkWrap,
54- constraints: const BoxConstraints (minWidth: 0.0 , minHeight: 0.0 ),
55- padding: EdgeInsets .all (10.0 ),
56- child: new Text (
57- name,
58- style: style,
59- textAlign: TextAlign .center,
60- ),
61- onPressed: () {
62- if (selectIndex != index) {
63- widget.selectItemChanged? .call (index);
64- }
65- setState (() {
66- selectIndex = index;
67- });
68- }),
55+ child: AnimatedSwitcher (
56+ transitionBuilder: (child, anim) {
57+ return ScaleTransition (child: child, scale: anim);
58+ },
59+ duration: Duration (milliseconds: 300 ),
60+ child: RawMaterialButton (
61+ key: ValueKey (index == selectIndex),
62+ materialTapTargetSize: MaterialTapTargetSize .shrinkWrap,
63+ constraints: const BoxConstraints (minWidth: 0.0 , minHeight: 0.0 ),
64+ padding: EdgeInsets .all (10.0 ),
65+ child: new Text (
66+ name,
67+ style: style,
68+ textAlign: TextAlign .center,
69+ ),
70+ onPressed: () {
71+ if (selectIndex != index) {
72+ widget.selectItemChanged? .call (index);
73+ }
74+ setState (() {
75+ selectIndex = index;
76+ });
77+ }),
78+ ),
6979 );
7080 }
7181
@@ -76,7 +86,10 @@ class _GSYSelectItemWidgetState extends State<GSYSelectItemWidget> {
7686 list.add (_renderItem (widget.itemNames[i], i));
7787 } else {
7888 list.add (_renderItem (widget.itemNames[i], i));
79- list.add (new Container (width: 1.0 , height: 25.0 , color: Color (GSYColors .subLightTextColor)));
89+ list.add (new Container (
90+ width: 1.0 ,
91+ height: 25.0 ,
92+ color: Color (GSYColors .subLightTextColor)));
8093 }
8194 }
8295 return list;
@@ -88,9 +101,10 @@ class _GSYSelectItemWidgetState extends State<GSYSelectItemWidget> {
88101 elevation: widget.elevation,
89102 margin: widget.margin,
90103 color: Theme .of (context).primaryColor,
91- shape: widget.shape ?? new RoundedRectangleBorder (
92- borderRadius: BorderRadius .all (Radius .circular (4.0 )),
93- ),
104+ shape: widget.shape ??
105+ new RoundedRectangleBorder (
106+ borderRadius: BorderRadius .all (Radius .circular (4.0 )),
107+ ),
94108 child: new Row (
95109 children: _renderList (),
96110 ));
0 commit comments