【发布时间】:2021-08-22 17:01:27
【问题描述】:
我正在开发 Flutter 2.2.1(频道稳定版)。我最近将我的 SDK 环境从 2.7.0 更改为 2.12.0 (sdk: ">=2.12.0 <3.0.0") 以添加插件,但我遇到了很多错误(尤其是关于 null 安全性)。其中之一是关于从 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; 行:
getter 'docs' 没有为类型 'Object' 定义。 尝试导入定义“docs”的库,将名称更正为现有 getter 的名称,或定义名为“docs”的 getter 或字段。
我是新的 Flutter 用户,我不明白在这里做什么。感谢您的帮助。
【问题讨论】:
标签: flutter dart google-cloud-firestore