参数类型 'Map<String, dynamic>Function()' 不能分配给参数类型 'Map<String, dynamic>' [英] The argument type &#39;Map&lt;String, dynamic&gt; Function()&#39; can&#39;t be assigned to the parameter type &#39;Map&lt;String, dynamic&gt;&#39;

查看:49
本文介绍了参数类型 '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;
}

参数类型'MapFunction()' 不能分配给参数类型 'Map'.

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

这篇关于参数类型 'Map<String, dynamic>Function()' 不能分配给参数类型 'Map<String, dynamic>'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆