参数类型'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>'
本文介绍了参数类型'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>
这篇关于参数类型'Map< String,dynamic>无法将Function()分配给参数类型“ Map< String,dynamic>”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文