2021年3月24日星期三

how to trigger search automatically when using SearchDelegate buildSuggestions in flutter

Now I am using SearchDelegate in flutter 2.0.1, this is my buildSuggestions code:

 Widget buildSuggestionComponent(List<ChannelSuggestion> suggestions, BuildContext context) {      return ListView.builder(        itemCount: suggestions.length,        itemBuilder: (context, index) {          return ListTile(            title: Text('${suggestions[index].name}'),            onTap: () async {              query = '${suggestions[index].name}';                          },          );        },      );    }  

when select the recommand text, I want to automatically trigger search event so I do not need to click search button. this is my search code:

@override    Widget buildResults(BuildContext context) {      var channelRequest = new ChannelRequest(pageNum: 1, pageSize: 10, name: query);      return buildResultImpl(channelRequest);    }      Widget buildResultImpl(ChannelRequest channelRequest) {      return FutureBuilder(          future: ChannelAction.searchChannel(channelRequest),          builder: (context, AsyncSnapshot snapshot) {            if (snapshot.hasData) {              List<Channel> channels = snapshot.data;              return buildResultsComponent(channels, context);            } else {              return Text("");            }            return Center(child: CircularProgressIndicator());          });    }  

what should I do to implement it? I have tried invoke buildResults function in buildSuggestionComponent but it seems not work.

https://stackoverflow.com/questions/66792056/how-to-trigger-search-automatically-when-using-searchdelegate-buildsuggestions-i March 25, 2021 at 10:05AM

没有评论:

发表评论