firebase - 参数类型 'Map<String, dynamic> Function()' 不能分配给参数类型 'Map<String, dynamic>'

标签 firebase flutter dart google-cloud-firestore

这最初可能有效,但在 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 Function()”分配给参数类型“Map”。

最佳答案

请尝试以下操作:

  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>

关于firebase - 参数类型 'Map<String, dynamic> Function()' 不能分配给参数类型 'Map<String, dynamic>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63597313/

相关文章:

javascript - Uncaught Error : Service database is not available firebase javascript

ios - Swift firebase 快照在数据存在时返回 null

java - Firebase Cloud Firestore 引用返回 null

flutter - 当用户使用 flutter 键入某些文本时,如何解析单词并将其替换为主题标签链接?

flutter - 在Flutter中将字符串转换为文件,反之亦然

flutter - Flutter:针对整个应用程序的SnackBar方法,修改Scaffold以跟踪当前显示的Scaffolds的BuildContext

dart - Dart按两个属性排序列表

android - 检索后动态链接未清除

json - 在Flutter中解析复杂的JSON

android - Flutter 修复 FlatButton 中不同图片大小相同的问题