gpt4 book ai didi

flutter - 带有Firestore的Flutter搜索代表

转载 作者:行者123 更新时间:2023-12-03 02:55:55 25 4
gpt4 key购买 nike

我正在使用Flutter Search Delegate实现搜索功能,并且数据存储在Firestore中。我不知道为什么会出现此错误。

Widget buildSuggestions(BuildContext context) {
return StreamBuilder(
stream: Firestore.instance.collection('todos').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return new Text('Loading...');

final results =
snapshot.data.documents.where((a) => a['title'].contains(query));

return ListView(
children: results.map<Widget>((a) => Text(a['title'])).toList(),
);
},
);
}

错误:
type '(dynamic) => dynamic' is not a subtype of type '(DocumentSnapshot) => bool' of 'test'

最佳答案

更换线

final results = snapshot.data.documents.where((a) => a['title'].contains(query));


final results = snapshot.data.documents.where((DocumentSnapshot a) => a.data['title'].contains(query));

和线
children: results.map<Widget>((a) => Text(a['title'])).toList()


children: results.map<Widget>((a) => Text(a.data['title'])).toList()

关于flutter - 带有Firestore的Flutter搜索代表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58587696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com