@@ -6,6 +6,15 @@ class Index extends StatefulWidget {
66}
77
88class _IndexState extends State <Index > {
9+ List <String > _tags = [
10+ 'cake' ,
11+ 'chicken' ,
12+ 'apple'
13+ ];
14+ String _action = '点击下面' ;
15+ List <String > _selected = [];
16+ String _choice = '点击下面' ;
17+
918 @override
1019 void initState () {
1120 super .initState ();
@@ -17,9 +26,161 @@ class _IndexState extends State<Index> {
1726 appBar: AppBar (
1827 title: Text ('Chip' ),
1928 ),
20- body: Center (
21- child: Text ('更新中' ),
29+ body: Container (
30+ padding: EdgeInsets .all (16.0 ),
31+ child: ListView (
32+ children: < Widget > [
33+ Container (
34+ child: Text ('chip:' ),
35+ ),
36+ ChipDemo (),
37+ Divider (),
38+ ChipDemoDelete (),
39+ Divider (),
40+ Container (
41+ child: Text ('ActionChip: $_action ' ),
42+ ),
43+ ActionChipDemo (),
44+ Divider (),
45+ Container (
46+ child: Text ('FilterChip: $_selected ' ),
47+ ),
48+ FilterChipDemo (),
49+ Divider (),
50+ Container (
51+ child: Text ('ChoiceChip: $_choice ' ),
52+ ),
53+ ChoiceChipDemo ()
54+ ],
55+ ),
56+ ),
57+ floatingActionButton: FloatingActionButton (
58+ child: Icon (Icons .restore),
59+ backgroundColor: Theme .of (context).primaryColor,
60+ onPressed: (){
61+ setState (() {
62+ _tags = [
63+ 'cake' ,
64+ 'chicken' ,
65+ 'apple'
66+ ];
67+ _selected = [];
68+ _action = '点击下面' ;
69+ _choice = '点击下面' ;
70+ });
71+ },
2272 ),
2373 );
2474 }
75+
76+ Widget ChipDemo () {
77+ return Wrap (
78+ spacing: 20.0 ,
79+ runSpacing: 8.0 ,
80+ children: < Widget > [
81+ Chip (
82+ label: Text ('Efox' ),
83+ ),
84+ Chip (
85+ label: Text ('backgroundColor' ),
86+ backgroundColor: Theme .of (context).primaryColor,
87+ labelStyle: TextStyle (color: Colors .white),
88+ // labelPadding: EdgeInsets.all(2.0),
89+ ),
90+ Chip (
91+ label: Text ('Efox Team' ),
92+ avatar: CircleAvatar (
93+ backgroundColor: Theme .of (context).primaryColor,
94+ child: Text ('E' ),
95+ ),
96+ ),
97+ Chip (
98+ label: Text ('Efox Team' ),
99+ avatar: CircleAvatar (
100+ backgroundImage: NetworkImage ('http://pic1.win4000.com/wallpaper/2019-04-02/5ca2ccd945964.jpg' ),
101+ ),
102+ ),
103+ Chip (
104+ label: Text ('City' ),
105+ onDeleted: (){},
106+ deleteIcon: Icon (Icons .delete, size: 26.0 ,),
107+ deleteIconColor: Theme .of (context).primaryColor,
108+ deleteButtonTooltipMessage: 'Remove this tag' ,
109+ )
110+ ],
111+ );
112+ }
113+
114+ Widget ChipDemoDelete () {
115+ return Wrap (
116+ spacing: 8.0 ,
117+ children: _tags.map ((tag){
118+ return Chip (
119+ label: Text (tag),
120+ onDeleted: () {
121+ setState (() {
122+ _tags.remove (tag);
123+ });
124+ },
125+ );
126+ }).toList (),
127+ );
128+ }
129+
130+ Widget ActionChipDemo () {
131+ return Wrap (
132+ spacing: 8.0 ,
133+ children: _tags.map ((tag){
134+ return ActionChip (
135+ label: Text (tag),
136+ onPressed: (){
137+ setState (() {
138+ _action = tag;
139+ });
140+ },
141+ );
142+ }).toList (),
143+ );
144+ }
145+
146+ Widget FilterChipDemo (){
147+ return Wrap (
148+ spacing: 8.0 ,
149+ children: _tags.map ((tag){
150+ return FilterChip (
151+ label: Text (tag),
152+ selected: _selected.contains (tag),
153+ selectedColor: Theme .of (context).primaryColor,
154+ onSelected: (value) {
155+ setState (() {
156+ if (_selected.contains (tag)) {
157+ _selected.remove (tag);
158+ } else {
159+ _selected.add (tag);
160+ }
161+ });
162+ },
163+ );
164+ }).toList (),
165+ );
166+ }
167+
168+ Widget ChoiceChipDemo () {
169+ return Wrap (
170+ spacing: 8.0 ,
171+ children: _tags.map ((tag) {
172+ return ChoiceChip (
173+ label: Text (tag),
174+ selectedColor: Theme .of (context).primaryColor,
175+ labelStyle: TextStyle (color: Colors .white),
176+ selected: _choice == tag,
177+ onSelected: (value) {
178+ setState (() {
179+ _choice = tag;
180+ });
181+ },
182+ );
183+ }).toList (),
184+ );
185+ }
25186}
0 commit comments