Flutter 实现对FutureBuilder数据的搜索
我已经实现了FutureBuilder来填充ListView。现在我想在这个填充的ListView上实现搜索功能。 下面是我如何做到这一点的代码:Flutter 实现对FutureBuilder数据的搜索,flutter,dart,search,async-await,future,Flutter,Dart,Search,Async Await,Future,我已经实现了FutureBuilder来填充ListView。现在我想在这个填充的ListView上实现搜索功能。 下面是我如何做到这一点的代码: FutureBuilder<ChatGroupListModel>( future: localChatGroupList, builder: (context,snapshot){ if (snapshot.connectionState == ConnectionState.done) {
FutureBuilder<ChatGroupListModel>(
future: localChatGroupList,
builder: (context,snapshot){
if (snapshot.connectionState == ConnectionState.done) {
if(snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.listChatGroupListModel.length,
itemBuilder: (context, index) {
return ChatTileWidget(
chatGroupModel: snapshot.data.listChatGroupListModel[index],
);
},
);
}else if (snapshot.hasError) {
return Text("${snapshot.error}");
}else return Center(
child: NoDataWidget(),
);
} else return Center(
child: CircularProgressIndicatorWidget()
);
},
);
FutureBuilder(
未来:localChatGroupList,
生成器:(上下文,快照){
if(snapshot.connectionState==connectionState.done){
if(snapshot.hasData){
返回ListView.builder(
itemCount:snapshot.data.listChatGroupListModel.length,
itemBuilder:(上下文,索引){
返回ChatTileWidget(
chatGroupModel:snapshot.data.listChatGroupListModel[索引],
);
},
);
}else if(snapshot.hasrerror){
返回文本(“${snapshot.error}”);
}埃尔斯返回中心(
子项:NoDataWidget(),
);
}埃尔斯返回中心(
子项:CircularProgressIndicatorWidget()
);
},
);
现在我想搜索这个填充的数据。请分享我如何在不调用API的情况下执行此操作。因此,您需要一个
StreamBuilder
(而不是FutureBuilder
)在每次键入“搜索”TextField
@pskink时返回一个新的快照。我不想在每次字符更改时都调用API。不,这并不意味着您必须调用API-您可以调用它一次,然后使用List.where
forfiltering@pskink请建议我如何实现。文本字段部分:child:TextField(onChanged:streamController.add)
现在您需要实现搜索流,比如:streamController.stream.debounce(持续时间(毫秒:500)).asyncMap((查询)=>calllist.where(),基于输入查询文本)