0

I have this code in SearchDelegate

class CustomSearchDelegate extends SearchDelegate<String> {

  @override
  List<Widget> buildActions(BuildContext context) {
    return [
      IconButton(
        icon: Icon(Icons.clear),
        onPressed: (){
          query = "";
        },
      )
    ];
  }

  @override
  Widget buildLeading(BuildContext context) {
    return IconButton(
      icon: Icon(Icons.arrow_back),
      onPressed: (){
        close(context, "");
      },
    );
  }


  @override
  Widget buildResults(BuildContext context) {
   close(context, query );
    return Container();
  }

  @override
  Widget buildSuggestions(BuildContext context) {
    return Container();        
  }

}

When I run it in debug mode, it works properly. But when I run in release mode, when confirming the search, it doesn't return to the page that called Search, it just returns container, even with the "close(context, query );" before in buildResults.

1 Answers1

0

I couldn't solve this specific problem, I really searched for any possible solution, but it seems to have to do with the way flutter generates the apk in release. In my case I just gave up using showSearch with SearchDelegate, and created a custom Appbar like a SearchBar. I'll leave below some links that I based it on

This was the one I used the most as an example

https://github.com/ahmed-alzahrani/Flutter_Search_Example

Custom AppBar Flutter

This option I haven't used but I found it interesting as another option to optimize your SearchBar

https://pub.dev/packages/flutter_search_bar