smartnsoft / flappy_search_bar

SearchBar widget to handle most of search cases
MIT License
172 stars 94 forks source link

How to clear search once an item is tapped? #32

Open pokhrelashok opened 4 years ago

pokhrelashok commented 4 years ago

How can we clear and remove focus from the search bar once an item is clicked?

caio-reimann commented 4 years ago

You need to use a SearchBarController in SearchBar(), then call _searchBarController.clear(); on selected item.

Ex:

final SearchBarController<City> _searchBarControllerCities = SearchBarController();

then on SearchBar...

                        SearchBar<City>(
                          searchBarController: _searchBarControllerCities,
                          ..........
                          onItemFound: (City city, int index) {
                            return FlatButton(
                              child: Text(city.searchCity),
                              onPressed: () {
                                searchBarControllerCities.clear();
                                // And anything else you need to do
                              },
                            );
                          },                          
                        ),