Created
June 29, 2019 10:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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