【发布时间】:2020-08-23 16:59:00
【问题描述】:
我想在 Firestore 数据中搜索,但该列表未显示来自 Firestore 的数据。我想用 Firestore 数据返回我的列表,但它没有显示我,我想根据我的选择在列表数据中搜索。
请告诉我哪里错了?
class serachDeligat extends SearchDelegate<String> {
Firestore _firestore = Firestore.instance;
String ref = 'items';
Future<List<DocumentSnapshot>> getSearch() async =>
await _firestore.collection(ref).getDocuments().then((snaps) {
return snaps.documents;
});
List<Map> search = <Map>[];
Future getDocs() async {
search = await (await getSearch()).map((item) => item.data).toList();
return search;
}
@override
void initState() {
getDocs();
}
@override
List<Widget> buildActions(BuildContext context) {
// TODO: implement buildActions
return [
IconButton(
icon: Icon(Icons.clear),
onPressed: () {
print('$search');
},
),
];
}
@override
Widget buildLeading(BuildContext context) {
// TODO: implement buildLeading
return IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
close(context, null);
},
);
}
@override
Widget buildResults(BuildContext context) {
return Container(
child: Center(),
);
}
@override
Widget buildSuggestions(BuildContext context) {
return Container();
}
}
【问题讨论】:
标签: firebase flutter google-cloud-firestore full-text-search flutter-test