【发布时间】:2021-06-28 02:16:09
【问题描述】:
我是一个颤抖的零安全菜鸟。我使用了下面的代码,但我收到了这个错误:
The argument type 'Map<String, dynamic>?' can't be assigned to the parameter type 'Map<String, dynamic>'
这看起来确实是一个 null 安全问题,但话说回来,可能必须这样做才能获得一个在 null 安全方面不同的文档流。
class DataService {
final _dataStore = FirebaseFirestore.instance;
Stream <List<Shop>> listAllShops() {
return _dataStore.collection('shops')
.snapshots()
.map((snapshot) => snapshot.docs
.map((document) => Shop.fromJson(document.data())) <<< error comes here
.toList());
}
}
我试过放一个 ?在不同的地方,但没有任何效果。
【问题讨论】:
标签: firebase flutter stream null-safety