Skip to content

Instantly share code, notes, and snippets.

@NishantDesai1306
Created June 29, 2019 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NishantDesai1306/7aec8ccdee0c0c662bde97eb26f7c493 to your computer and use it in GitHub Desktop.
Save NishantDesai1306/7aec8ccdee0c0c662bde97eb26f7c493 to your computer and use it in GitHub Desktop.
adding callback functions so that default app bar can communicate with search bar
// add this method to default app bar class
// this will get executed when user pressed back arrow on search bar
cancelSearch() {
// remove search bar from stack
setState(() {
isInSearchMode = false;
});
// change search value to ''
onSearchQueryChange('');
// run the rippple animation in reverse direction
_controller.reverse();
}
// add this method to default app bar class
onSearchQueryChange(String query) {
// do anything with this string you can pass it back to Scaffold and
// handle it there as well, it's up to you
print('search $query');
}
// pass these callback functions to SearchBar in render method of DefaultAppBar
SearchBar(
onCancelSearch: cancelSearch,
onSearchQueryChanged: onSearchQueryChange,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment