【问题标题】:Flutter-Firestore "The argument type 'Map<String, dynamic> Function()' can't be assigned to the parameter type 'Map<String, dynamic>"Flutter-Firestore “参数类型 'Map<String, dynamic> Function()' 不能分配给参数类型 'Map<String, dynamic>”
【发布时间】:2021-03-23 20:07:35
【问题描述】:

我尝试在 Firebase Firestore 中查看我的数据。但是这个错误出现在我的 firestore_service.dart 文件中。你能帮我解决这个错误吗?

"参数类型'Map Function()'不能赋值给参数类型'Map"

这是我的 firestore_service.dart

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:esrimarket/note.dart';
import 'package:flutter/foundation.dart';

class FirestoreService {
  static final FirestoreService _firestoreService =
      FirestoreService._internal();
  Firestore _db = Firestore.instance;

  FirestoreService._internal();

  factory FirestoreService() {
    return _firestoreService;
  }

  getNotes(){
    return _db
    .collection('notes')
    .snapshots()
    .map((snapshot)=>snapshot.documents.map((doc)=>Note.fromMap(doc.data, doc.documentID)));
  }
}

这是我的 note.dart 文件

class Note{
  final String name;
  final String price;
  final String quantity;
  final String id;

  Note({this.name, this.price, this.quantity, this.id});

  Note.fromMap(Map<String,dynamic> data, String id):
    name=data["name"],
    price=data["price"],
    quantity=data["quantity"],
    id=id;
}

【问题讨论】:

    标签: firebase flutter google-cloud-firestore google-cloud-functions flutter-web


    【解决方案1】:

    成员data 后面缺少括号,因为它是一个函数:

    Note.fromMap(doc.data(), doc.documentID)
    
                         ^^
    

    【讨论】:

      猜你喜欢
      • 2020-12-15
      • 2020-12-27
      • 2021-08-29
      • 2021-10-02
      • 1970-01-01
      • 2023-04-05
      • 2021-08-03
      • 2021-05-17
      相关资源
      最近更新 更多