我正在开发 Flutter 2.2.1(通道稳定)。我最近将 SDK 的环境从 2.7.0 更改为 2.12.0 (sdk: ">=2.12.0 <3.0.0"
)为了添加插件,我遇到了很多错误(尤其是关于零安全性)。其中之一是关于从 firestore 中提取数据(我正在使用cloud_firestore: ^2.2.1
).
My code:
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;
:
没有为类型“Object”定义 getter“docs”。
尝试导入定义“docs”的库,将名称更正为现有 getter 的名称,或者定义名为“docs”的 getter 或字段。
我是一个新的 flutter 用户,我不明白在这里该怎么做。感谢您的帮助。