@@ -91,163 +91,183 @@ class _SearchFieldSampleState extends State<SearchFieldSample> {
91
91
},
92
92
child: Icon (Icons .add),
93
93
),
94
- body: Padding (
95
- padding: const EdgeInsets .all (8.0 ),
96
- child: ListView (
97
- children: [
98
- TextFormField (
94
+ body: GestureDetector (
95
+ onTap: () {
96
+ FocusScope .of (context).unfocus ();
97
+ },
98
+ child: Padding (
99
+ padding: const EdgeInsets .all (8.0 ),
100
+ child: ListView (
101
+ children: [
102
+ TextFormField (
103
+ autovalidateMode: AutovalidateMode .onUserInteraction,
104
+ decoration: InputDecoration (
105
+ labelText: 'Flutter TextFormField' ,
106
+ ),
107
+ validator: (value) {
108
+ if (value == null || value.length < 4 ) {
109
+ return 'error' ;
110
+ }
111
+ return null ;
112
+ }),
113
+ SizedBox (
114
+ height: 50 ,
115
+ ),
116
+ SearchField <String >(
117
+ maxSuggestionsInViewPort: 7 ,
118
+ suggestions: suggestions
119
+ .map (
120
+ (e) => SearchFieldListItem <String >(
121
+ e,
122
+ item: e,
123
+ child: Padding (
124
+ padding: const EdgeInsets .all (8.0 ),
125
+ child: Text (e),
126
+ ),
127
+ ),
128
+ )
129
+ .toList (),
130
+ ),
131
+ SizedBox (
132
+ height: 50 ,
133
+ ),
134
+ SearchField (
135
+ hint: 'Basic SearchField' ,
136
+ initialValue: SearchFieldListItem <String >('ABC' ),
137
+ suggestions: ['ABC' , 'DEF' , 'GHI' , 'JKL' ]
138
+ .map (SearchFieldListItem <String >.new )
139
+ .toList (),
140
+ suggestionState: Suggestion .expand,
141
+ ),
142
+ SizedBox (
143
+ height: 50 ,
144
+ ),
145
+ Pagination (),
146
+ SizedBox (
147
+ height: 50 ,
148
+ ),
149
+ NetworkSample (),
150
+ SizedBox (
151
+ height: 50 ,
152
+ ),
153
+ SearchField (
154
+ suggestionDirection: SuggestionDirection .flex,
155
+ onSearchTextChanged: (query) {
156
+ final filter = suggestions
157
+ .where ((element) =>
158
+ element.toLowerCase ().contains (query.toLowerCase ()))
159
+ .toList ();
160
+ return filter
161
+ .map ((e) => SearchFieldListItem <String >(e,
162
+ child: searchChild (e)))
163
+ .toList ();
164
+ },
165
+ initialValue: SearchFieldListItem <String >('United States' ),
166
+ controller: searchController,
99
167
autovalidateMode: AutovalidateMode .onUserInteraction,
100
- decoration: InputDecoration (
101
- labelText: 'Flutter TextFormField' ,
102
- ),
103
168
validator: (value) {
104
- if (value == null || value.length < 4 ) {
105
- return 'error ' ;
169
+ if (value == null || ! suggestions. contains ( value.trim ()) ) {
170
+ return 'Enter a valid country name ' ;
106
171
}
107
172
return null ;
108
- }),
109
- SizedBox (
110
- height: 50 ,
111
- ),
112
- SizedBox (
113
- height: 50 ,
114
- ),
115
- SearchField (
116
- hint: 'Basic SearchField' ,
117
- initialValue: SearchFieldListItem <String >('ABC' ),
118
- suggestions: ['ABC' , 'DEF' , 'GHI' , 'JKL' ]
119
- .map (SearchFieldListItem <String >.new )
120
- .toList (),
121
- suggestionState: Suggestion .expand,
122
- ),
123
- SizedBox (
124
- height: 50 ,
125
- ),
126
- Pagination (),
127
- SizedBox (
128
- height: 50 ,
129
- ),
130
- NetworkSample (),
131
- SizedBox (
132
- height: 50 ,
133
- ),
134
- SearchField (
135
- suggestionDirection: SuggestionDirection .flex,
136
- onSearchTextChanged: (query) {
137
- final filter = suggestions
138
- .where ((element) =>
139
- element.toLowerCase ().contains (query.toLowerCase ()))
140
- .toList ();
141
- return filter
142
- .map ((e) =>
143
- SearchFieldListItem <String >(e, child: searchChild (e)))
144
- .toList ();
145
- },
146
- initialValue: SearchFieldListItem <String >('United States' ),
147
- controller: searchController,
148
- autovalidateMode: AutovalidateMode .onUserInteraction,
149
- validator: (value) {
150
- if (value == null || ! suggestions.contains (value.trim ())) {
151
- return 'Enter a valid country name' ;
152
- }
153
- return null ;
154
- },
155
- onSubmit: (x) {},
156
- autofocus: false ,
157
- key: const Key ('searchfield' ),
158
- hint: 'Search by country name' ,
159
- itemHeight: 50 ,
160
- onTapOutside: (x) {
161
- // focus.unfocus();
162
- },
163
- scrollbarDecoration: ScrollbarDecoration (
164
- thickness: 12 ,
165
- radius: Radius .circular (6 ),
166
- trackColor: Colors .grey,
167
- trackBorderColor: Colors .red,
168
- thumbColor: Colors .orange,
169
- ),
170
- suggestionStyle:
171
- const TextStyle (fontSize: 18 , color: Colors .black),
172
- searchStyle: TextStyle (fontSize: 18 , color: Colors .black),
173
- suggestionItemDecoration: BoxDecoration (
174
- // color: Colors.grey[100],
175
- // borderRadius: BorderRadius.circular(10),
176
- border: Border (
177
- bottom: BorderSide (
178
- color: Colors .grey.shade200,
179
- width: 1 ,
180
- ),
173
+ },
174
+ onSubmit: (x) {},
175
+ autofocus: false ,
176
+ key: const Key ('searchfield' ),
177
+ hint: 'Search by country name' ,
178
+ itemHeight: 50 ,
179
+ onTapOutside: (x) {
180
+ // focus.unfocus();
181
+ },
182
+ scrollbarDecoration: ScrollbarDecoration (
183
+ thickness: 12 ,
184
+ radius: Radius .circular (6 ),
185
+ trackColor: Colors .grey,
186
+ trackBorderColor: Colors .red,
187
+ thumbColor: Colors .orange,
181
188
),
182
- ),
183
- searchInputDecoration: InputDecoration (
184
- hintStyle: TextStyle (fontSize: 18 , color: Colors .grey),
185
- focusedBorder: OutlineInputBorder (
186
- borderRadius: BorderRadius .circular (24 ),
187
- borderSide: const BorderSide (
188
- width: 1 ,
189
- color: Colors .orange,
190
- style: BorderStyle .solid,
189
+ suggestionStyle:
190
+ const TextStyle (fontSize: 18 , color: Colors .black),
191
+ searchStyle: TextStyle (fontSize: 18 , color: Colors .black),
192
+ suggestionItemDecoration: BoxDecoration (
193
+ // color: Colors.grey[100],
194
+ // borderRadius: BorderRadius.circular(10),
195
+ border: Border (
196
+ bottom: BorderSide (
197
+ color: Colors .grey.shade200,
198
+ width: 1 ,
199
+ ),
191
200
),
192
201
),
193
- border: OutlineInputBorder (
194
- borderRadius: BorderRadius .circular (24 ),
195
- borderSide: const BorderSide (
196
- width: 1 ,
197
- color: Colors .black,
198
- style: BorderStyle .solid,
202
+ searchInputDecoration: InputDecoration (
203
+ hintStyle: TextStyle (fontSize: 18 , color: Colors .grey),
204
+ focusedBorder: OutlineInputBorder (
205
+ borderRadius: BorderRadius .circular (24 ),
206
+ borderSide: const BorderSide (
207
+ width: 1 ,
208
+ color: Colors .orange,
209
+ style: BorderStyle .solid,
210
+ ),
211
+ ),
212
+ border: OutlineInputBorder (
213
+ borderRadius: BorderRadius .circular (24 ),
214
+ borderSide: const BorderSide (
215
+ width: 1 ,
216
+ color: Colors .black,
217
+ style: BorderStyle .solid,
218
+ ),
219
+ ),
220
+ contentPadding: const EdgeInsets .symmetric (
221
+ horizontal: 20 ,
199
222
),
200
223
),
201
- contentPadding: const EdgeInsets .symmetric (
202
- horizontal: 20 ,
203
- ),
224
+ suggestionsDecoration: SuggestionDecoration (
225
+ // border: Border.all(color: Colors.orange),
226
+ elevation: 8.0 ,
227
+ selectionColor: Colors .grey.shade100,
228
+ hoverColor: Colors .purple.shade100,
229
+ gradient: LinearGradient (
230
+ colors: [
231
+ Color (0xfffc466b ),
232
+ Color .fromARGB (255 , 103 , 128 , 255 )
233
+ ],
234
+ stops: [0.25 , 0.75 ],
235
+ begin: Alignment .topLeft,
236
+ end: Alignment .bottomRight,
237
+ ),
238
+ borderRadius: BorderRadius .only (
239
+ bottomLeft: Radius .circular (10 ),
240
+ bottomRight: Radius .circular (10 ),
241
+ )),
242
+ suggestions: suggestions
243
+ .map ((e) =>
244
+ SearchFieldListItem <String >(e, child: searchChild (e)))
245
+ .toList (),
246
+ focusNode: focus,
247
+ suggestionState: Suggestion .expand,
248
+ onSuggestionTap: (SearchFieldListItem <String > x) {},
204
249
),
205
- suggestionsDecoration: SuggestionDecoration (
206
- // border: Border.all(color: Colors.orange),
207
- elevation: 8.0 ,
208
- selectionColor: Colors .grey.shade100,
209
- hoverColor: Colors .purple.shade100,
210
- gradient: LinearGradient (
211
- colors: [
212
- Color (0xfffc466b ),
213
- Color .fromARGB (255 , 103 , 128 , 255 )
214
- ],
215
- stops: [0.25 , 0.75 ],
216
- begin: Alignment .topLeft,
217
- end: Alignment .bottomRight,
218
- ),
219
- borderRadius: BorderRadius .only (
220
- bottomLeft: Radius .circular (10 ),
221
- bottomRight: Radius .circular (10 ),
222
- )),
223
- suggestions: suggestions
224
- .map ((e) =>
225
- SearchFieldListItem <String >(e, child: searchChild (e)))
226
- .toList (),
227
- focusNode: focus,
228
- suggestionState: Suggestion .expand,
229
- onSuggestionTap: (SearchFieldListItem <String > x) {},
230
- ),
231
- SizedBox (
232
- height: 50 ,
233
- ),
234
- SearchField (
235
- enabled: false ,
236
- hint: 'Disabled SearchField' ,
237
- suggestions: ['ABC' , 'DEF' , 'GHI' , 'JKL' ]
238
- .map (SearchFieldListItem <String >.new )
239
- .toList (),
240
- suggestionState: Suggestion .expand,
241
- ),
242
- SizedBox (
243
- height: 50 ,
244
- ),
245
- NetworkSample (),
246
- Text (
247
- 'Counter: $counter ' ,
248
- style: Theme .of (context).textTheme.bodyLarge,
249
- ),
250
- ],
250
+ SizedBox (
251
+ height: 50 ,
252
+ ),
253
+ SearchField (
254
+ enabled: false ,
255
+ hint: 'Disabled SearchField' ,
256
+ suggestions: ['ABC' , 'DEF' , 'GHI' , 'JKL' ]
257
+ .map (SearchFieldListItem <String >.new )
258
+ .toList (),
259
+ suggestionState: Suggestion .expand,
260
+ ),
261
+ SizedBox (
262
+ height: 50 ,
263
+ ),
264
+ NetworkSample (),
265
+ Text (
266
+ 'Counter: $counter ' ,
267
+ style: Theme .of (context).textTheme.bodyLarge,
268
+ ),
269
+ ],
270
+ ),
251
271
),
252
272
));
253
273
}
0 commit comments