我正在尝试使用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
将会是
..。我该如何解决这个问题呢?更改要采用的所有函数
并假设密钥是一个
是一个相当丑陋的解决方案。
发布于 2021-03-01 23:02:04
你可以试试这个:
var stringMap = mapFromFirestore.map((key,value) => MapEntry(key as String, dynamic.from(value));
https://stackoverflow.com/questions/50159766
复制相似问题