Skip to content

Commit 0219785

Browse files
committed
Fix: Issue #155
1 parent 2925d80 commit 0219785

File tree

6 files changed

+284
-205
lines changed

6 files changed

+284
-205
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#### [1.0.7] - July 21, 2024
2+
3+
- Fix: Scroll to selected Sugggestion Issue Fix: [Issue #155](https://github.com/maheshmnj/searchfield/issues/155)
4+
- Fix: maxSuggestionInViewport did not show correct number of suggestions.
5+
16
#### [1.0.6] - July 10, 2024
27

38
- Option was not being selected on search [Issue #136](https://github.com/maheshmnj/searchfield/issues/136)

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [searchfield: ^1.0.6](https://pub.dev/packages/searchfield)
1+
# [searchfield: ^1.0.7](https://pub.dev/packages/searchfield)
22

33
<a href="https://github.com/maheshmnj/searchfield" rel="noopener" target="_blank"><img src="https://img.shields.io/badge/platform-flutter-ff69b4.svg" alt="Flutter Platform Badge"></a>
44
<a href="https://pub.dev/packages/searchfield"><img src="https://img.shields.io/pub/v/searchfield.svg" alt="Pub"></a>
@@ -281,7 +281,7 @@ The position of suggestions is dynamic based on the space available for the sugg
281281
- `initialValue` : The initial value to be set in searchfield when its rendered, if not specified it will be empty.
282282
- `inputType`: Keyboard Type for SearchField
283283
- `inputFormatters`: Input Formatter for SearchField
284-
- `itemHeight` : height of each suggestion Item, (defaults to 35.0).
284+
- `itemHeight` : height of each suggestion Item, (defaults to 51.0).
285285
- `marginColor` : Color for the margin between the suggestions.
286286
- `maxSuggestionsInViewPort` : The max number of suggestions that can be shown in a viewport.
287287
- `offset` : suggestion List offset from the searchfield, The top left corner of the searchfield is the origin (0,0).

example/lib/main.dart

+167-147
Original file line numberDiff line numberDiff line change
@@ -91,163 +91,183 @@ class _SearchFieldSampleState extends State<SearchFieldSample> {
9191
},
9292
child: Icon(Icons.add),
9393
),
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,
99167
autovalidateMode: AutovalidateMode.onUserInteraction,
100-
decoration: InputDecoration(
101-
labelText: 'Flutter TextFormField',
102-
),
103168
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';
106171
}
107172
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,
181188
),
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+
),
191200
),
192201
),
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,
199222
),
200223
),
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) {},
204249
),
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+
),
251271
),
252272
));
253273
}

0 commit comments

Comments
 (0)