0

I got the error after follow the tutorial of Firebase for Flutter: https://codelabs.developers.google.com/codelabs/flutter-firebase/#4.

I'm using Andriod Studio 4.0.1.

dev_dependencies:
  flutter_test:
    sdk: flutter
  cloud_firestore: ^0.14.0+2 

Error:

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);
                          ^

Solution from @Peter Haddad:

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

Another Error:

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)
matrixxx
  • 33
  • 5
  • I have no issue when executing their code. Maybe you could post yours to see what isn't working. – Lulupointu Sep 29 '20 at 09:47
  • I'm follow the tutorial by copy code from website and I didn't change it. I'm no idea why got the error. – matrixxx Sep 29 '20 at 09:54
  • For the other error check my answer here https://stackoverflow.com/questions/63492211/no-firebase-app-default-has-been-created-call-firebase-initializeapp-in/63492262#63492262 – Peter Haddad Sep 29 '20 at 13:44

1 Answers1

1

You are using a new version of cloud firestore. Therefore you have to do the following now:

this.fromMap(snapshot.data(), reference: snapshot.reference);
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • These changes to the FlutterFire libraries were recent, so you're quite likely to find outdated materials for the near future. I recommend keeping this migration guide handy: https://firebase.flutter.dev/docs/migration – Frank van Puffelen Sep 29 '20 at 13:41
  • I am facing this issue can you solve this @PeterHaddad and FrankvanPuffelen I am stuck and cant solve this its been a week now plz needed your help https://stackoverflow.com/q/69053706/13984728 – Mithson Sep 04 '21 at 08:56