Skip to content

Commit

Permalink
prepare for release v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maheshj01 committed Nov 29, 2024
1 parent 1e5a50e commit 168f690
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 136 deletions.
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
#### [1.2.0] - November 28, 2024

- [Breaking]: Handle selected Value on Client Side [Issue: #191](https://github.com/maheshj01/searchfield/issues/191)

**Before**

The package sets the selectedValue automatically inside the component, which leads to issues when navigating or selecting suggestions
```dart
SearchField(
hint: 'Basic SearchField',
dynamicHeight: true,
maxSuggestionBoxHeight: 300,
initialValue: SearchFieldListItem<String>('ABC'),
suggestions: dynamicHeightSuggestion
.map(SearchFieldListItem<String>.new)
.toList(),
suggestionState: Suggestion.expand,
),
```

**After**

Now the client should handle te selectedValue explicitly in the client code (consumer code) by using the onSuggestionTap callback. This approach simplifies the API and provides more accurate control over the internal state of the package.

```dart
var selectedValue = SearchFieldListItem<String>('ABC');
SearchField(
hint: 'Basic SearchField',
dynamicHeight: true,
maxSuggestionBoxHeight: 300,
onSuggestionTap: (SearchFieldListItem<String> item) {
setState(() {
selectedValue = item;
});
},
selectedValue: selectedValue,
suggestions: dynamicHeightSuggestion
.map(SearchFieldListItem<String>.new)
.toList(),
suggestionState: Suggestion.expand,
),
```
- Fixes: [Issue: #178](https://github.com/maheshj01/searchfield/issues/178), [Issue: #155](https://github.com/maheshj01/searchfield/issues/155)

- Fixes: [Issue: #151](https://github.com/maheshj01/searchfield/issues/151) Clarifies use of SuggestionAction and now defaults to `SuggestionState.unfocus` without having to use `FocusNode` on client side.

Huge thanks to all contributors and supporters.
Happy Thanksgiving! 🦃

#### [1.1.9] - November 25, 2024
- [regression] Fix: Keyboard navigation does not work [Issue: 183](https://github.com/maheshj01/searchfield/issues/182)

Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [searchfield: ^1.1.9](https://pub.dev/packages/searchfield)
# [searchfield: ^1.2.0](https://pub.dev/packages/searchfield)

<a href="https://github.com/maheshj01/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 @@ -48,6 +48,8 @@ Use the Widget
#### Example1

```dart
var selectedValue = null;
SearchField<Country>(
suggestions: countries
.map(
Expand All @@ -70,6 +72,12 @@ SearchField<Country>(
],
),
),
selectedValue: selectedValue,
onSuggestionTap: (SearchFieldListItem<Country> x) {
setState(() {
selectedValue = x.item;
});
},
),
).toList(),
),
Expand Down Expand Up @@ -126,7 +134,7 @@ SearchField(
focusNode: focus,
suggestionState: Suggestion.expand,
onSuggestionTap: (SearchFieldListItem<String> x) {
focus.unfocus();
},
),
```
Expand Down Expand Up @@ -219,11 +227,13 @@ Form(
.toList(),
focusNode: focus,
suggestionState: Suggestion.expand,
selectedValue: selectedValue,
onSuggestionTap: (SearchFieldListItem<String> x) {
focus.unfocus();
setState(() {
selectedValue = x.item;
});
},
),
));
```

<img src="https://user-images.githubusercontent.com/31410839/104081674-2ec10980-5256-11eb-9712-6b18e3e67f4a.gif" width="360"/>
Expand Down
File renamed without changes.
153 changes: 22 additions & 131 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// import 'package:example/pagination.dart';
import 'package:example/custom.dart';
import 'package:example/dynamic_height.dart';
import 'package:example/network_sample.dart';
import 'package:example/pagination.dart';
import 'package:flutter/material.dart';
import 'package:searchfield/searchfield.dart';

Expand All @@ -13,6 +9,7 @@ void main() {
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
Expand All @@ -22,7 +19,6 @@ class MyApp extends StatelessWidget {
useMaterial3: true,
brightness: Brightness.light,
),
themeMode: ThemeMode.system,
darkTheme: ThemeData(
colorSchemeSeed: Colors.blue,
useMaterial3: true,
Expand Down Expand Up @@ -67,126 +63,26 @@ class _SearchFieldSampleState extends State<SearchFieldSample> {
'Nigeria',
'Egypt',
];
selected = suggestions[0];
super.initState();
}

int suggestionsCount = 12;
final focus = FocusNode();
final dynamicHeightSuggestion = [
'ABC\nABC\nABC\nABC',
'DEF\nABC',
'GHI',
'JKL\nABC',
'ABC',
'123\n123',
'123\n123',
'123\n123',
'123\n123',
'123\n123',
'123\n123',
'àkajsddddddddddddddddddddddddddddddddddddddddddddddddddđ',
'àkajsddddddddddddddddddddddddddddddddddddddddddddddddddđ',
'àkajsddddddddddddddddddddddddddddddddddddddddddddddddddđ',
'àkajsddddddddddddddddddddddddddddddddddddddddddddddddddđ',
'àkajsddddddddddddddddddddddddddddddddddddddddddddddddddđ',
];
final TextEditingController searchController = TextEditingController();
var suggestions = <String>[];
int counter = 0;
var selected = '';
var selectedValue = SearchFieldListItem<String>('United States');
var selectedValue = null;
@override
Widget build(BuildContext context) {
Widget searchChild(x, {bool isSelected = false}) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text(x,
style: TextStyle(
fontSize: 18, color: isSelected ? Colors.green : null)),
fontSize: 18,
color: isSelected ? Colors.green : Colors.black)),
);
return Scaffold(
appBar: AppBar(title: Text('Searchfield Demo')),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
children: [
UserSelect(),
SizedBox(
height: 20,
),
DynamicHeightExample(),
SizedBox(
height: 20,
),
SearchField(
hint: 'Basic SearchField',
dynamicHeight: true,
maxSuggestionBoxHeight: 300,
onSuggestionTap: (SearchFieldListItem<String> item) {
setState(() {
selectedValue = item;
});
},
selectedValue: selectedValue,
suggestions:
suggestions.map(SearchFieldListItem<String>.new).toList(),
suggestionState: Suggestion.expand,
),
SizedBox(
height: 20,
),
TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
decoration: InputDecoration(
labelText: 'Flutter TextFormField',
),
validator: (value) {
if (value == null || value.length < 4) {
return 'error';
}
return null;
}),
SizedBox(
height: 50,
),
Pagination(),
SizedBox(
height: 50,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: SearchField<String>(
maxSuggestionsInViewPort: 11,
suggestionAction: SuggestionAction.unfocus,
searchInputDecoration: SearchInputDecoration(
hintText: 'Search',
cursorColor: Colors.blue,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
selectedValue: selectedValue,
onSuggestionTap: (SearchFieldListItem<String> item) {
setState(() {
selectedValue = item;
});
},
suggestions: suggestions
.map(
(e) => SearchFieldListItem<String>(e,
item: e,
child: searchChild(e, isSelected: e == selected)),
)
.toList(),
),
),
SizedBox(
height: 50,
),
NetworkSample(),
SizedBox(
height: 50,
),
SearchField(
suggestionDirection: SuggestionDirection.flex,
onSearchTextChanged: (query) {
Expand All @@ -199,8 +95,7 @@ class _SearchFieldSampleState extends State<SearchFieldSample> {
SearchFieldListItem<String>(e, child: searchChild(e)))
.toList();
},
selectedValue: SearchFieldListItem<String>('United States'),
controller: searchController,
selectedValue: selectedValue,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || !suggestions.contains(value.trim())) {
Expand All @@ -213,9 +108,6 @@ class _SearchFieldSampleState extends State<SearchFieldSample> {
key: const Key('searchfield'),
hint: 'Search by country name',
itemHeight: 50,
onTapOutside: (x) {
// focus.unfocus();
},
scrollbarDecoration: ScrollbarDecoration(
thickness: 12,
radius: Radius.circular(6),
Expand Down Expand Up @@ -280,29 +172,28 @@ class _SearchFieldSampleState extends State<SearchFieldSample> {
.map((e) =>
SearchFieldListItem<String>(e, child: searchChild(e)))
.toList(),
focusNode: focus,
suggestionState: Suggestion.expand,
onSuggestionTap: (SearchFieldListItem<String> x) {},
),
SizedBox(
height: 50,
onSuggestionTap: (SearchFieldListItem<String> x) {
setState(() {
selectedValue = x;
});
},
),
SizedBox(height: 20),
SearchField(
enabled: false,
hint: 'Disabled SearchField',
suggestions: ['ABC', 'DEF', 'GHI', 'JKL']
.map(SearchFieldListItem<String>.new)
.toList(),
hint: 'Basic SearchField',
dynamicHeight: true,
maxSuggestionBoxHeight: 300,
onSuggestionTap: (SearchFieldListItem<String> item) {
setState(() {
selectedValue = item;
});
},
selectedValue: selectedValue,
suggestions:
suggestions.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 168f690

Please sign in to comment.