当前位置: 首页 > 知识库问答 >
问题:

无法将参数类型“Book”分配给参数类型“Map”。dart(参数类型不可分配)

戎元忠
2023-03-14
                 actions: [
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: TextButton(
                          onPressed: () {
                              _bookCollectionReference.add(Book(
                              userId: FirebaseAuth.instance.currentUser.uid,
                              title: book.title,,
                              author: book.author,
                              photoUrl: book.photoUrl,
                              publishedDate: book.publishedDate,
                              description: book.description,
                              pageCount: book.pageCount,
                              categories: book.categories,
                            ));
                          },
                          child: Text('Save')),
                    ),

///课本

地图

共有1个答案

张鸿宝
2023-03-14

您忘记通过调用. toMap()将Dart Class转换为Map(json)

在onPressed方法中尝试以下代码:

_bookCollectionReference.add(
  Book(
    userId: FirebaseAuth.instance.currentUser.uid,
    title: book.title,,
    author: book.author,
    photoUrl: book.photoUrl,
    publishedDate: book.publishedDate,
    description: book.description,
    pageCount: book.pageCount,
    categories: book.categories,
  ).toMap(),
);
 类似资料: