参数类型'Map< String,dynamic>无法将Function()分配给参数类型“ Map< String,dynamic>”

参数类型'Map< String,dynamic>无法将Function()分配给参数类型“ Map< String,dynamic>”

问题描述:

这最初可以正常工作,但是在更新Firebase之后,现在却给了我这个错误。我在给出错误的部分添加了星号。错误消息已添加到代码下方。

This could initially was working but after firebase update, it is now giving me this error. I have added asterisks to the part giving the error. The error message has been added beneath the code.

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< String,dynamic>不能将Function()'分配给参数类型'Map< String,dynamic>'。

The argument type 'Map<String, dynamic> Function()' can't be assigned to the parameter type 'Map<String, dynamic>'.

请尝试以下操作:

  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>