【发布时间】:2021-08-27 08:26:32
【问题描述】:
我最近将我的 Flutter 升级到了最新版本,但我遇到了所有 null 安全错误。
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('restaurants')
.doc(partnerId)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
final restaurant = snapshot.data;
startTime = restaurant['startTime'].toDate();
endTime = restaurant['endTime'].toDate();
当我将餐厅 [''] 分配给任何变量时,我收到以下错误。
方法'[]'不能被无条件调用,因为接收者 可以为“空”。
如果我这样做 - restaurant!['endTime'].toDate();,就会出现新错误
没有为“对象”类型定义运算符“[]”。尝试定义 运算符“[]”。
【问题讨论】:
标签: flutter dart google-cloud-firestore nullable