=2.12.0 关于 flutter - 错误 -6ren">
gpt4 book ai didi

flutter - 错误 : The getter 'docs' isn't defined for the type 'Object'

转载 作者:行者123 更新时间:2023-12-04 12:32:30 26 4
gpt4 key购买 nike

我正在研究 Flutter 2.2.1( channel 稳定)。我最近将我的 SDK 的环境从 2.7.0 更改为 2.12.0 ( sdk: ">=2.12.0 <3.0.0" ) 以添加插件,但我遇到了很多错误(尤其是关于空安全的错误)。其中之一是关于从 firestore 中提取数据(我正在使用 cloud_firestore: ^2.2.1 )。
我的代码:

StreamBuilder(
stream: FirebaseFirestore.instance
.collection('towns/${widget.townId}/beacons')
.orderBy('monument')
.snapshots(),
builder: (ctx, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting)
return CircularProgressIndicator();
final beacons = snapshot.data!.docs; // Error here
return ListView.builder(
physics:
NeverScrollableScrollPhysics(),
shrinkWrap:
true,
itemCount: beacons.length,
itemBuilder: (ctx, index) {
if (beacons[index]['visibility'] == true) {
return BeaconCard(
title: beacons[index]['title'],
monument: beacons[index]['monument'],
image: beacons[index]['image'],
duration: beacons[index]['duration'],
distance: 0,
townId: widget.townId,
uuid: beacons[index]['uuid'],
fontsizeValue: widget.fontsizeValue,
languageId: widget.languageId,
);
}
return Container();
});
}),
错误大约是 docs在线 final beacons = snapshot.data!.docs; :

The getter 'docs' isn't defined for the type 'Object'.Try importing the library that defines 'docs', correcting the name to the name of an existing getter, or defining a getter or field named 'docs'.


我是一个新的 flutter 用户,我不明白在这里做什么。谢谢你的帮助。

最佳答案

请传递快照的类型。在这种情况下

StreamBuilder<QuerySnapshot>

关于 flutter - 错误 : The getter 'docs' isn't defined for the type 'Object' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67840643/

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