【发布时间】:2021-07-28 02:15:32
【问题描述】:
在 Flutter 中,我有一个称为供应商的集合,我将根据其集合的图像来获取集合
这是我的代码:
class _TopPickStoreState extends State<TopPickStore>{
StoreService _storeServices = StoreService();
@override
Widget build(BuildContext context){
return Container(
child: StreamBuilder<QuerySnapshot>(
stream: _storeServices.getTopPickedStore(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapShot){
if(!snapShot.hasData)return CircularProgressIndicator();
return Column(
children: [
Flexible(
child: ListView(
scrollDirection: Axis.horizontal,
children: snapShot.data.docs.map((DocumentSnapshot document){
return Container(
width: 80,
child: Column(
children: [
Image.network(document['imageUrl']),
]
),
)
;}).toList(),
),
)
],
);
}
),
);
} }
这是获取集合的函数:
import 'package:cloud_firestore/cloud_firestore.dart';
class StoreService{
getTopPickedStore(){
return FirebaseFirestore.instance.collection('vendors')
.where('accVerified', isEqualTo:true)
.where('isTopPicked',isEqualTo: true)
.orderBy('shopName');
}
}
我收到了这个错误信息:
类型 'Query' 不是类型 'Stream 谁能帮我解决这个问题?
【问题讨论】:
-
问题是由
getTopPickedStore()引起的,发布这个函数。因为它返回query对象,但您的流构建器是查询快照。决定你要使用哪一个,然后就可以修复了 -
我已经放了getTopPickedStore()函数,希望你能详细解释一下如何解决这个问题。非常感谢
-
我添加了一个答案。基本上,函数中当前写入的内容是查询。这意味着它是一组说明,告诉 Firebase 在哪里以及要查找什么,但您不告诉它之后要做什么。必须告诉
get()或snapshots(),才能真正进入firebase,获取这些文档,然后将它们作为查询快照返回。
标签: flutter dart firebase-authentication syntax-error snapshot