Skip to content

Commit

Permalink
Fix: Issue #155
Browse files Browse the repository at this point in the history
  • Loading branch information
maheshj01 committed Jul 21, 2024
1 parent 2925d80 commit 0219785
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 205 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#### [1.0.7] - July 21, 2024

- Fix: Scroll to selected Sugggestion Issue Fix: [Issue #155](https://github.com/maheshmnj/searchfield/issues/155)
- Fix: maxSuggestionInViewport did not show correct number of suggestions.

#### [1.0.6] - July 10, 2024

- Option was not being selected on search [Issue #136](https://github.com/maheshmnj/searchfield/issues/136)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [searchfield: ^1.0.6](https://pub.dev/packages/searchfield)
# [searchfield: ^1.0.7](https://pub.dev/packages/searchfield)

<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>
<a href="https://pub.dev/packages/searchfield"><img src="https://img.shields.io/pub/v/searchfield.svg" alt="Pub"></a>
Expand Down Expand Up @@ -281,7 +281,7 @@ The position of suggestions is dynamic based on the space available for the sugg
- `initialValue` : The initial value to be set in searchfield when its rendered, if not specified it will be empty.
- `inputType`: Keyboard Type for SearchField
- `inputFormatters`: Input Formatter for SearchField
- `itemHeight` : height of each suggestion Item, (defaults to 35.0).
- `itemHeight` : height of each suggestion Item, (defaults to 51.0).
- `marginColor` : Color for the margin between the suggestions.
- `maxSuggestionsInViewPort` : The max number of suggestions that can be shown in a viewport.
- `offset` : suggestion List offset from the searchfield, The top left corner of the searchfield is the origin (0,0).
Expand Down
314 changes: 167 additions & 147 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,163 +91,183 @@ class _SearchFieldSampleState extends State<SearchFieldSample> {
},
child: Icon(Icons.add),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
children: [
TextFormField(
body: GestureDetector(
onTap: () {
FocusScope.of(context).unfocus();
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
children: [
TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
decoration: InputDecoration(
labelText: 'Flutter TextFormField',
),
validator: (value) {
if (value == null || value.length < 4) {
return 'error';
}
return null;
}),
SizedBox(
height: 50,
),
SearchField<String>(
maxSuggestionsInViewPort: 7,
suggestions: suggestions
.map(
(e) => SearchFieldListItem<String>(
e,
item: e,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(e),
),
),
)
.toList(),
),
SizedBox(
height: 50,
),
SearchField(
hint: 'Basic SearchField',
initialValue: SearchFieldListItem<String>('ABC'),
suggestions: ['ABC', 'DEF', 'GHI', 'JKL']
.map(SearchFieldListItem<String>.new)
.toList(),
suggestionState: Suggestion.expand,
),
SizedBox(
height: 50,
),
Pagination(),
SizedBox(
height: 50,
),
NetworkSample(),
SizedBox(
height: 50,
),
SearchField(
suggestionDirection: SuggestionDirection.flex,
onSearchTextChanged: (query) {
final filter = suggestions
.where((element) =>
element.toLowerCase().contains(query.toLowerCase()))
.toList();
return filter
.map((e) => SearchFieldListItem<String>(e,
child: searchChild(e)))
.toList();
},
initialValue: SearchFieldListItem<String>('United States'),
controller: searchController,
autovalidateMode: AutovalidateMode.onUserInteraction,
decoration: InputDecoration(
labelText: 'Flutter TextFormField',
),
validator: (value) {
if (value == null || value.length < 4) {
return 'error';
if (value == null || !suggestions.contains(value.trim())) {
return 'Enter a valid country name';
}
return null;
}),
SizedBox(
height: 50,
),
SizedBox(
height: 50,
),
SearchField(
hint: 'Basic SearchField',
initialValue: SearchFieldListItem<String>('ABC'),
suggestions: ['ABC', 'DEF', 'GHI', 'JKL']
.map(SearchFieldListItem<String>.new)
.toList(),
suggestionState: Suggestion.expand,
),
SizedBox(
height: 50,
),
Pagination(),
SizedBox(
height: 50,
),
NetworkSample(),
SizedBox(
height: 50,
),
SearchField(
suggestionDirection: SuggestionDirection.flex,
onSearchTextChanged: (query) {
final filter = suggestions
.where((element) =>
element.toLowerCase().contains(query.toLowerCase()))
.toList();
return filter
.map((e) =>
SearchFieldListItem<String>(e, child: searchChild(e)))
.toList();
},
initialValue: SearchFieldListItem<String>('United States'),
controller: searchController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || !suggestions.contains(value.trim())) {
return 'Enter a valid country name';
}
return null;
},
onSubmit: (x) {},
autofocus: false,
key: const Key('searchfield'),
hint: 'Search by country name',
itemHeight: 50,
onTapOutside: (x) {
// focus.unfocus();
},
scrollbarDecoration: ScrollbarDecoration(
thickness: 12,
radius: Radius.circular(6),
trackColor: Colors.grey,
trackBorderColor: Colors.red,
thumbColor: Colors.orange,
),
suggestionStyle:
const TextStyle(fontSize: 18, color: Colors.black),
searchStyle: TextStyle(fontSize: 18, color: Colors.black),
suggestionItemDecoration: BoxDecoration(
// color: Colors.grey[100],
// borderRadius: BorderRadius.circular(10),
border: Border(
bottom: BorderSide(
color: Colors.grey.shade200,
width: 1,
),
},
onSubmit: (x) {},
autofocus: false,
key: const Key('searchfield'),
hint: 'Search by country name',
itemHeight: 50,
onTapOutside: (x) {
// focus.unfocus();
},
scrollbarDecoration: ScrollbarDecoration(
thickness: 12,
radius: Radius.circular(6),
trackColor: Colors.grey,
trackBorderColor: Colors.red,
thumbColor: Colors.orange,
),
),
searchInputDecoration: InputDecoration(
hintStyle: TextStyle(fontSize: 18, color: Colors.grey),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(24),
borderSide: const BorderSide(
width: 1,
color: Colors.orange,
style: BorderStyle.solid,
suggestionStyle:
const TextStyle(fontSize: 18, color: Colors.black),
searchStyle: TextStyle(fontSize: 18, color: Colors.black),
suggestionItemDecoration: BoxDecoration(
// color: Colors.grey[100],
// borderRadius: BorderRadius.circular(10),
border: Border(
bottom: BorderSide(
color: Colors.grey.shade200,
width: 1,
),
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(24),
borderSide: const BorderSide(
width: 1,
color: Colors.black,
style: BorderStyle.solid,
searchInputDecoration: InputDecoration(
hintStyle: TextStyle(fontSize: 18, color: Colors.grey),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(24),
borderSide: const BorderSide(
width: 1,
color: Colors.orange,
style: BorderStyle.solid,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(24),
borderSide: const BorderSide(
width: 1,
color: Colors.black,
style: BorderStyle.solid,
),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 20,
),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 20,
),
suggestionsDecoration: SuggestionDecoration(
// border: Border.all(color: Colors.orange),
elevation: 8.0,
selectionColor: Colors.grey.shade100,
hoverColor: Colors.purple.shade100,
gradient: LinearGradient(
colors: [
Color(0xfffc466b),
Color.fromARGB(255, 103, 128, 255)
],
stops: [0.25, 0.75],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10),
)),
suggestions: suggestions
.map((e) =>
SearchFieldListItem<String>(e, child: searchChild(e)))
.toList(),
focusNode: focus,
suggestionState: Suggestion.expand,
onSuggestionTap: (SearchFieldListItem<String> x) {},
),
suggestionsDecoration: SuggestionDecoration(
// border: Border.all(color: Colors.orange),
elevation: 8.0,
selectionColor: Colors.grey.shade100,
hoverColor: Colors.purple.shade100,
gradient: LinearGradient(
colors: [
Color(0xfffc466b),
Color.fromARGB(255, 103, 128, 255)
],
stops: [0.25, 0.75],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10),
)),
suggestions: suggestions
.map((e) =>
SearchFieldListItem<String>(e, child: searchChild(e)))
.toList(),
focusNode: focus,
suggestionState: Suggestion.expand,
onSuggestionTap: (SearchFieldListItem<String> x) {},
),
SizedBox(
height: 50,
),
SearchField(
enabled: false,
hint: 'Disabled SearchField',
suggestions: ['ABC', 'DEF', 'GHI', 'JKL']
.map(SearchFieldListItem<String>.new)
.toList(),
suggestionState: Suggestion.expand,
),
SizedBox(
height: 50,
),
NetworkSample(),
Text(
'Counter: $counter',
style: Theme.of(context).textTheme.bodyLarge,
),
],
SizedBox(
height: 50,
),
SearchField(
enabled: false,
hint: 'Disabled SearchField',
suggestions: ['ABC', 'DEF', 'GHI', 'JKL']
.map(SearchFieldListItem<String>.new)
.toList(),
suggestionState: Suggestion.expand,
),
SizedBox(
height: 50,
),
NetworkSample(),
Text(
'Counter: $counter',
style: Theme.of(context).textTheme.bodyLarge,
),
],
),
),
));
}
Expand Down
Loading

0 comments on commit 0219785

Please sign in to comment.