首页 > 解决方案 > 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)

标签: firebaseflutterdartgoogle-cloud-firestore

解决方案


您正在使用新版本的 Cloud Firestore。因此,您现在必须执行以下操作:

this.fromMap(snapshot.data(), reference: snapshot.reference);

推荐阅读