firebase - Flutter Firebase教程错误
问题描述
遵循 Firebase for Flutter 的教程后出现错误:https ://codelabs.developers.google.com/codelabs/flutter-firebase/#4 。
我正在使用 Andriod Studio 4.0.1。
dev_dependencies:
flutter_test:
sdk: flutter
cloud_firestore: ^0.14.0+2
错误:
lib/main.dart:84:31: Error: The argument type 'Map<String, dynamic> Function()' can't be assigned to the parameter type 'Map<String, dynamic>'.
- 'Map' is from 'dart:core'.
: this.fromMap(snapshot.data, reference: snapshot.reference);
^
@Peter Haddad 的解决方案:
this.fromMap(snapshot.data(), reference: snapshot.reference);
另一个错误:
The following FirebaseException was thrown building MyHomePage(dirty, state: _MyHomePageState#257aa):
[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
The relevant error-causing widget was:
MyHomePage file:///D:/Private/Project/workspace_flutter/baby_names/lib/main.dart:12:13
When the exception was thrown, this was the stack:
#0 MethodChannelFirebase.app (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:118:5)
#1 Firebase.app (package:firebase_core/src/firebase.dart:52:41)
#2 FirebaseFirestore.instance (package:cloud_firestore/src/firestore.dart:43:21)
#3 Firestore.instance (package:cloud_firestore/src/firestore.dart:246:30)
#4 _MyHomePageState._buildBody (package:baby_names/main.dart:35:25)
解决方案
您正在使用新版本的 Cloud Firestore。因此,您现在必须执行以下操作:
this.fromMap(snapshot.data(), reference: snapshot.reference);
推荐阅读
- kubernetes - 列出正在为服务提供服务的 pod
- karate - 空手道:如何在空手道中初始化 RemoteWebDriver
- python - 用神经网络识别钞票,我必须裁剪数据集的图像吗
- javascript - 当我的 Angular 库项目使用“--prod”选项启动时,扩展内置类的方法(通过 JS 的“.prototype”属性)不起作用
- javascript - 首先通过节点后端传递所有http请求和React Routes进行会话验证,然后返回路径
- c - 为什么C不能直接分配数组,但可以在结构中分配数组?
- android - LiveData 完成加载时触发代码?
- angular - 如何将对象转换为对象数组?在角
- ios - Xcode 中的签名配置文件冲突
- wordpress-theming - 函数.php 文件