简体   繁体   English

不能将参数类型“Book”分配给参数类型“Map”<String, dynamic> &#39;.dart(argument_type_not_assignable)

[英]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.

相关问题 参数类型'列表<string> ' 不能分配给 Dart 上的参数类型 'String'.dart(argument_type_not_assignable)</string> - The argument type 'List<String>' can't be assigned to the parameter type 'String'.dart(argument_type_not_assignable) on the Dart 不能将参数类型“String”分配给参数类型“Route”<Object?> &#39;.dart(argument_type_not_assignable) - The argument type 'String' can't be assigned to the parameter type 'Route<Object?>'.dart(argument_type_not_assignable) 参数类型 &#39;Null&#39; 不能分配给参数类型 &#39;FirebaseUser&#39;.dart(argument_type_not_assignable) - The argument type 'Null' can't be assigned to the parameter type 'FirebaseUser'.dart(argument_type_not_assignable) 错误:[dart] 无法将参数类型“Context”分配给参数类型“BuildContext”。 [argument_type_not_assignable] - error: [dart] The argument type 'Context' can't be assigned to the parameter type 'BuildContext'. [argument_type_not_assignable] 如何解决“参数类型‘对象?’ 不能分配给参数类型 'String'.dart(argument_type_not_assignable)”? - How can I resolve "The argument type 'Object?' can't be assigned to the parameter type 'String'.dart(argument_type_not_assignable)"? 错误:参数类型“用户?” 不能分配给参数类型“用户”。 (argument_type_not_assignable 在 [food_app] lib\auth\sign_in.dart:36) - error: The argument type 'User?' can't be assigned to the parameter type 'User'. (argument_type_not_assignable at [food_app] lib\auth\sign_in.dart:36) Flutter Dart - 无法将参数类型“String”分配给参数类型“Map”<String,dynamic> &#39; - Flutter Dart - the argument type 'String' can't be assigned to the parameter type 'Map<String,dynamic>' 不能将参数类型“地图动态动态”分配给参数类型“地图字符串动态” - the argument type 'map dynamic dynamic ' can't be assigned to the parameter type 'map string dynamic' 参数类型'Map<dynamic, dynamic> ' 不能分配给参数类型 'Map<string, dynamic> '</string,></dynamic,> - The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>' 参数类型&#39;查询<Object?> &#39;不能分配给参数类型&#39;查询<Map<String, dynamic> &gt;&#39;。 (users_api.dart) - The argument type 'Query<Object?>' can't be assigned to the parameter type 'Query<Map<String, dynamic>>'. (users_api.dart)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM