Flutter-Firestore "The argument type 'Map<String, dynamic> Function()' can't be assigned to the parameter type 'Map<String, dynamic>"
Flutter-Firestore "The argument type 'Map<String, dynamic> Function()' can't be assigned to the parameter type 'Map<String, dynamic>"
我尝试在 firebase firestore 中查看我的数据。但是这个错误是我的 firestore_service.dart file.Can 你帮我解决这个错误。
"参数类型 'Map<String, dynamic> 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;
}
您在成员 data
后缺少括号,因为它是一个函数:
Note.fromMap(doc.data(), doc.documentID)
^^
我尝试在 firebase firestore 中查看我的数据。但是这个错误是我的 firestore_service.dart file.Can 你帮我解决这个错误。
"参数类型 'Map<String, dynamic> 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;
}
您在成员 data
后缺少括号,因为它是一个函数:
Note.fromMap(doc.data(), doc.documentID)
^^