I have an appBar with a search button, which when pressed returns a custom DataSearch class that extends SearchDelegate.
When I close the search page (from the device's go back button or from the widget), I need to execute a certain function first. However the function is only executed from the below widget and not when the device's "BACK" button is pressed.
(Image below)
Here's my code:
class DataSearch extends SearchDelegate<String> {
@override
List<Widget> buildActions(BuildContext context) {
// ...
}
@override
Widget buildLeading(BuildContext context) {
return IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
function_I_need_to_execute();
close(context, null);
},
);
}
@override
Widget buildResults(BuildContext context) {
// ...
}
@override
Widget buildSuggestions(BuildContext context) {
// ...
}
}
I've tried this, but no changes:
@override
void close(BuildContext context, String result) {
super.close(context, result);
function_I_need_to_execute();
}
I'm considering using the WillPopScope widget but I'm not sure where it fits in the delegate.
Image: