这可能是最初的工作,但在firebase更新后,它现在给我这个错误.我在给出错误的部分加了星号.错误消息已添加到代码下面.

import 'package:cloud_firestore/cloud_firestore.dart';

class Record {
  final String name;
  final int totalVotes;
  final DocumentReference reference;

  Record.fromMap(Map<String, dynamic> map, {this.reference})
      : assert(map['name'] != null),
        assert(map['totalVotes'] != null),
        name = map['name'],
        totalVotes = map['totalVotes'];

  Record.fromSnapshot(DocumentSnapshot snapshot)
      : this.fromMap(**snapshot.data**, reference: snapshot.reference);

  @override
  String toString() => "Record<$name:$totalVotes>";
}

class Voters {
  String uid;
  String voteId;
  String markedVoteOption;
}

参数类型‘Map&lt;String,Dynamic&gt;function()’不能分配给参数类型‘Map&lt;String,Dynamic&gt;’.

推荐答案

try 以下操作:

  Record.fromSnapshot(DocumentSnapshot snapshot)
      : this.fromMap(snapshot.data(), reference: snapshot.reference);

data()是一种方法:

  /// Contains all the data of this [DocumentSnapshot].
  Map<String, dynamic> data() {
    return _CodecUtility.replaceDelegatesWithValueInMap(
        _delegate.data(), _firestore);
  }

返回Map<String, dynamic>

Dart相关问答推荐

如何在 Dart 中实现继承?

创建默认应用时 FirebaseOptions 不能为空

flutter: 使用提供程序时,状态在热重载时丢失

Flutter | Dart:URI的目标不存在

在Flatter中滚动列表视图时,网络图像一直消失?

Dart:Streams与 ValueNotifiers

Flutter中图像纵横比的变化

如何从Flatter应用程序中导航到网页?(OAuth)

将DateTime转换为ISO 8601

Flutter列表视图底部溢出

如何左对齐 Flutter 中的 OutlineButton 图标

将Flutter的 PageView 与屏幕左侧对齐

带有 Dart 的 CORS,我如何让它工作?

如何在 Dart 中使用 char 类型?

Dart 中使用的const关键字是什么?

Dart 转换列表的每个元素

Dart 如何匹配然后替换正则表达式

Dart 中不同的 Map 实现有什么区别?

Angular.js 和 Angular.dart 的区别?

在 Dart 中验证邮箱地址?