@@ -16,9 +16,51 @@ class MyApp extends StatelessWidget {
16
16
}
17
17
}
18
18
19
+ class AppProfile {
20
+ final String name;
21
+ final String email;
22
+ final String imageUrl;
23
+
24
+ const AppProfile (this .name, this .email, this .imageUrl);
25
+
26
+ @override
27
+ bool operator == (Object other) =>
28
+ identical (this , other) ||
29
+ other is AppProfile &&
30
+ runtimeType == other.runtimeType &&
31
+ name == other.name;
32
+
33
+ @override
34
+ int get hashCode => name.hashCode;
35
+
36
+ @override
37
+ String toString () {
38
+ return 'Profile{$name }' ;
39
+ }
40
+ }
41
+
19
42
class MyHomePage extends StatelessWidget {
20
43
@override
21
44
Widget build (BuildContext context) {
45
+ const mockResults = < AppProfile > [
46
+ AppProfile (
'Stock Man' ,
'[email protected] ' ,
47
+ 'https://d2gg9evh47fn9z.cloudfront.net/800px_COLOURBOX4057996.jpg' ),
48
+ AppProfile (
'Paul' ,
'[email protected] ' ,
49
+ 'https://mbtskoudsalg.com/images/person-stock-image-png.png' ),
50
+ AppProfile (
'Fred' ,
'[email protected] ' ,
51
+ 'https://media.istockphoto.com/photos/feeling-great-about-my-corporate-choices-picture-id507296326' ),
52
+ AppProfile (
'Bera' ,
'[email protected] ' ,
53
+ 'https://upload.wikimedia.org/wikipedia/commons/7/7c/Profile_avatar_placeholder_large.png' ),
54
+ AppProfile (
'John' ,
'[email protected] ' ,
55
+ 'https://upload.wikimedia.org/wikipedia/commons/7/7c/Profile_avatar_placeholder_large.png' ),
56
+ AppProfile (
'Thomas' ,
'[email protected] ' ,
57
+ 'https://upload.wikimedia.org/wikipedia/commons/7/7c/Profile_avatar_placeholder_large.png' ),
58
+ AppProfile (
'Norbert' ,
'[email protected] ' ,
59
+ 'https://upload.wikimedia.org/wikipedia/commons/7/7c/Profile_avatar_placeholder_large.png' ),
60
+ AppProfile (
'Marina' ,
'[email protected] ' ,
61
+ 'https://upload.wikimedia.org/wikipedia/commons/7/7c/Profile_avatar_placeholder_large.png' ),
62
+ ];
63
+
22
64
return Scaffold (
23
65
appBar: AppBar (
24
66
title: Text ('Flutter FormBuilder Example' ),
@@ -27,10 +69,47 @@ class MyHomePage extends StatelessWidget {
27
69
margin: EdgeInsets .all (15.0 ),
28
70
child: FormBuilder (
29
71
context,
30
- // autovalidate: true,
72
+ autovalidate: true ,
31
73
// showResetButton: true,
32
74
// resetButtonContent: Text("Clear Form"),
33
75
controls: [
76
+ FormBuilderInput .chipsInput (
77
+ label: 'Test' ,
78
+ attribute: 'chips_test' ,
79
+ require: true ,
80
+ suggestionsCallback: (String query) {
81
+ if (query.length != 0 ) {
82
+ return mockResults.where ((profile) {
83
+ return profile.name.contains (query) ||
84
+ profile.email.contains (query);
85
+ }).toList (growable: false );
86
+ } else {
87
+ return const < AppProfile > [];
88
+ }
89
+ },
90
+ chipBuilder: (context, state, profile) {
91
+ return InputChip (
92
+ key: ObjectKey (profile),
93
+ label: Text (profile.name),
94
+ avatar: CircleAvatar (
95
+ backgroundImage: NetworkImage (profile.imageUrl),
96
+ ),
97
+ onDeleted: () => state.deleteChip (profile),
98
+ materialTapTargetSize: MaterialTapTargetSize .shrinkWrap,
99
+ );
100
+ },
101
+ suggestionBuilder: (context, state, profile) {
102
+ return ListTile (
103
+ key: ObjectKey (profile),
104
+ leading: CircleAvatar (
105
+ backgroundImage: NetworkImage (profile.imageUrl),
106
+ ),
107
+ title: Text (profile.name),
108
+ subtitle: Text (profile.email),
109
+ onTap: () => state.selectSuggestion (profile),
110
+ );
111
+ },
112
+ ),
34
113
FormBuilderInput .textField (
35
114
type: FormBuilderInput .TYPE_TEXT ,
36
115
attribute: "name" ,
@@ -68,12 +147,12 @@ class MyHomePage extends StatelessWidget {
68
147
require: true ,
69
148
),
70
149
FormBuilderInput .textField (
71
- type: FormBuilderInput .TYPE_PHONE ,
72
- attribute: "phone" ,
73
- label: "Phone" ,
74
- hint: "Including country code (+254)"
75
- //require: true,
76
- ),
150
+ type: FormBuilderInput .TYPE_PHONE ,
151
+ attribute: "phone" ,
152
+ label: "Phone" ,
153
+ hint: "Including country code (+254)"
154
+ //require: true,
155
+ ),
77
156
FormBuilderInput .password (
78
157
attribute: "password" ,
79
158
label: "Password" ,
@@ -114,23 +193,21 @@ class MyHomePage extends StatelessWidget {
114
193
],
115
194
),
116
195
FormBuilderInput .checkbox (
117
- label: "I accept the terms and conditions" ,
118
- attribute: "accept_terms" ,
119
- hint: "Kindly make sure you've read all the terms and conditions" ,
120
- validator: (value){
121
- if (! value)
122
- return "Accept terms to continue" ;
123
- }
124
- ),
196
+ label: "I accept the terms and conditions" ,
197
+ attribute: "accept_terms" ,
198
+ hint:
199
+ "Kindly make sure you've read all the terms and conditions" ,
200
+ validator: (value) {
201
+ if (! value) return "Accept terms to continue" ;
202
+ }),
125
203
FormBuilderInput .switchInput (
126
204
label: "I accept the terms and conditions" ,
127
205
attribute: "accept_terms_switch" ,
128
- hint: "Kindly make sure you've read all the terms and conditions" ,
129
- validator: (value){
130
- if (! value)
131
- return "Accept terms to continue" ;
132
- }
133
- ),
206
+ hint:
207
+ "Kindly make sure you've read all the terms and conditions" ,
208
+ validator: (value) {
209
+ if (! value) return "Accept terms to continue" ;
210
+ }),
134
211
FormBuilderInput .slider (
135
212
label: "Slider" ,
136
213
attribute: "slider" ,
@@ -157,41 +234,42 @@ class MyHomePage extends StatelessWidget {
157
234
hint: "Hint" ,
158
235
),
159
236
FormBuilderInput .segmentedControl (
160
- label: "Movie Rating (Archer)" ,
161
- attribute: "movie_rating" ,
162
- require: true ,
163
- options: [
164
- FormBuilderInputOption (
165
- value: 1 ,
166
- ),
167
- FormBuilderInputOption (
168
- value: 2 ,
169
- ),
170
- FormBuilderInputOption (
171
- value: 3 ,
172
- ),
173
- FormBuilderInputOption (
174
- value: 4 ,
175
- ),
176
- FormBuilderInputOption (
177
- value: 5 ,
178
- ),
179
- FormBuilderInputOption (
180
- value: 6 ,
181
- ),
182
- FormBuilderInputOption (
183
- value: 7 ,
184
- ),
185
- FormBuilderInputOption (
186
- value: 8 ,
187
- ),
188
- FormBuilderInputOption (
189
- value: 9 ,
190
- ),
191
- FormBuilderInputOption (
192
- value: 10 ,
193
- ),
194
- ]),
237
+ label: "Movie Rating (Archer)" ,
238
+ attribute: "movie_rating" ,
239
+ require: true ,
240
+ options: [
241
+ FormBuilderInputOption (
242
+ value: 1 ,
243
+ ),
244
+ FormBuilderInputOption (
245
+ value: 2 ,
246
+ ),
247
+ FormBuilderInputOption (
248
+ value: 3 ,
249
+ ),
250
+ FormBuilderInputOption (
251
+ value: 4 ,
252
+ ),
253
+ FormBuilderInputOption (
254
+ value: 5 ,
255
+ ),
256
+ FormBuilderInputOption (
257
+ value: 6 ,
258
+ ),
259
+ FormBuilderInputOption (
260
+ value: 7 ,
261
+ ),
262
+ FormBuilderInputOption (
263
+ value: 8 ,
264
+ ),
265
+ FormBuilderInputOption (
266
+ value: 9 ,
267
+ ),
268
+ FormBuilderInputOption (
269
+ value: 10 ,
270
+ ),
271
+ ],
272
+ ),
195
273
],
196
274
onChanged: () {
197
275
print ("Form value changed" );
0 commit comments