首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >颤动云场恢复Map<String,dynamic>错误

颤动云场恢复Map<String,dynamic>错误
EN

Stack Overflow用户
提问于 2018-05-04 00:23:25
回答 5查看 24.3K关注 0票数 6

我正在尝试使用Flutter和Firestore构建一个应用程序。当使用StreamBuilder从Firestore加载集合以在ListView中显示它时,我得到以下错误

代码语言:javascript
运行
复制
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

这就是我想要从

代码语言:javascript
运行
复制
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'] );

  /*

  ...

  */
}

以及我想如何使用它

代码语言:javascript
运行
复制
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();
    },
  ),
);

依赖关系:

代码语言:javascript
运行
复制
dependencies:
  flutter:
    sdk: flutter

  cloud_firestore: ^0.6.3
  firebase_messaging: ^0.2.4

Firestore仅允许

密钥和

值为,但

,核心语言类型。The The The

插件将文档数据保存在

..。我以为

inside all

将会是

..。我该如何解决这个问题呢?更改要采用的所有函数

并假设密钥是一个

是一个相当丑陋的解决方案。

EN

Stack Overflow用户

发布于 2021-03-01 23:02:04

你可以试试这个:

代码语言:javascript
运行
复制
var stringMap = mapFromFirestore.map((key,value) => MapEntry(key as String, dynamic.from(value));
票数 0
EN
查看全部 5 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50159766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档