flutter - 参数类型“书”不能分配给参数类型“地图”'.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')),
),
///课本
Map<String, dynamic> toMap() { return { 'title': title, 'user_id': userId, 'author': author, 'notes': notes, 'photo_url': photoUrl, 'published_date': publishedDate, 'description ':描述,'page_count':pageCount,'categories':类别,}; } }
解决方案
您忘记通过调用 .toMap() 将 Dart 类转换为 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(),
);
推荐阅读
- php - 如何使用 PHP 中的某个值合并两个数组而不重复?
- algorithm - 如何找出上升的词(或列表中越来越流行的词)
- python - 如何为我的简单纸牌游戏压缩详细代码?
- javascript - 在嵌套 for 循环内的超测响应后修改对象的问题
- java - 如何从 JSON 响应中提取 ID 并将其用作 JMeter 中另一个 HTTP 请求中的路径变量
- javascript - 进度条动画在 IE 11 中不起作用
- java - 对接口的静态引用
- ethereum - Solidity 中的动态数组
- amazon-s3 - 用于镶木地板的 Grok 分类器
- node.js - ERR_CONNECTION_RESET:错误当我尝试使用 node.js/multer 上传大文件时,部署在弹性 beanstalk -nginx 服务器