[英]The argument type 'Book' can't be assigned to the parameter type 'Map<String, dynamic>'.dart(argument_type_not_assignable)
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')),
),
///class book ///课本
Map<String, dynamic> toMap() { return { 'title': title, 'user_id': userId, 'author': author, 'notes': notes, 'photo_url': photoUrl, 'published_date': publishedDate, 'description': description, 'page_count': pageCount, 'categories': categories, }; Map<String, dynamic> toMap() { return { 'title':title,'user_id':userId,'author':作者,'notes':notes,'photo_url':photoUrl,'published_date':publishedDate,'description ':描述,'page_count':pageCount,'categories':类别,}; } }
} }
You forgot to convert you Dart Class to Map (json) by calling .toMap()您忘记通过调用 .toMap() 将 Dart Class 转换为 Map (json)
Try the following code inside your onPressed method:在 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(),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.