首页 > 解决方案 > 为什么firebase颤振代码不起作用并出现错误?

问题描述

这是我无法理解的颤振代码来解决下面提到的问题。

`导入'包:cloud_firestore/cloud_firestore.dart';

 class Book {
  String bookName = "";
  String authorName = "";


  late DocumentReference documentReference;
  Book(this.bookName,this.authorName);


  Book.fromMap(Map<String, dynamic> map, this.documentReference) {
  bookName = map["bookName"];
  authorName = map["authorName"];}
  Book.fromSnapshot(DocumentSnapshot snapshot)
  :this.fromMap(snapshot.data, documentReference:snapshot.reference);


  toJson(){
    return{'bookName':bookName, "authorName": authorName};} }

运行代码时出现此错误

错误 :

需要 2 个位置参数,但找到了 1 个。参数类型“对象?Function()' 不能分配给参数类型'Map<String, dynamic>'。未定义命名参数“documentReference”。尝试将名称更正为现有命名参数的名称,或使用名称“documentReference”定义命名参数。尝试添加缺少的参数。

标签: firebaseflutter

解决方案


推荐阅读