我正在尝试使用Flutter和Firestore构建一个应用程序。当使用StreamBuilder从Firestore加载集合以在ListView中显示它时,我得到以下错误
The following assertion was thrown building StreamBuilder(dirty, state:
I/flutter (26287): _StreamBuilderBaseState>#d5638):
I/flutter (26287): type '_InternalLinkedHashMap' is not a subtype of type 'Map'
I/flutter (26287): where
I/flutter (26287): _InternalLinkedHashMap is from dart:collection
I/flutter (26287): Map is from dart:core
I/flutter (26287): String is from dart:core
这就是我想要从
class Creator {
const Creator({this.creatorId, this.name});
Creator.fromDoc(DocumentSnapshot doc) : this.fromMap(doc.data);
Creator.fromMap(Map map) :
assert(map.containsKey('creatorId'),
assert(map.containsKey('name'),
this ( creatorId: map['creatorId'], name: map['name'] );
/*
...
*/
}
以及我想如何使用它
return Scaffold(
appBar: AppBar(title: new Text('Creators')),
body: StreamBuilder(
stream: CreatorRepo.getCreators().map>((creators) {
return creators.documents.map((c) => Creator.fromSnapshot(c)).toList();
}),
builder: (BuildContext context, snapshot) {
if ( snapshot.hasData ) {
return ListView.builder(
itemCount: snapshot.data.length,
builder: (context, index) {
final creator = snapshot.data[index];
return ExpansionTile(
title: Text(creator.name),
children: [
Text(creator.creatorId),
],
);
},
);
}
return const CircularProgressIndicator();
},
),
);
依赖关系:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.6.3
firebase_messaging: ^0.2.4
Firestore仅允许
密钥和
值为,但
,核心语言类型。The The The
插件将文档数据保存在
..。我以为
inside all
将会是
..。我该如何解决这个问题呢?更改要采用的所有函数
并假设密钥是一个
是一个相当丑陋的解决方案。
发布于 2018-05-16 07:38:28
我相信这是因为从Firebase返回的Map不是
但是取而代之的是
..。
请参见
https://github.com/flutter/flutter/issues/17417
与此相关的问题。
发布于 2019-05-17 00:35:58
使用
..。这将创建一个新的
从
,如果它发现一个键不是
..。
发布于 2019-09-18 06:53:39
我也有这个问题,并用--
Map var = {'item': 0, 'name': 'John'}
而不是未指定的地图。
Map var = {'item': 0, 'name': 'John'}
https://stackoverflow.com/questions/50159766
复制相似问题