No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() in Flutter and Firebase

后端 未结 9 1273
离开以前
离开以前 2020-11-22 15:32

I am building a flutter App and I have integrated Firebase but I keep getting this error when I click on a button either to register, login or logout. I have seen other peop

相关标签:
9条回答
  • 2020-11-22 15:57
    1. Add to pubspec.yaml

      firebase_core :
      
    2. add to main.dart

      import 'package:firebase_core/firebase_core.dart';
      
      void main() async {
         WidgetsFlutterBinding.ensureInitialized();
         await Firebase.initializeApp();
         runApp(MyApp());
      }
      
    0 讨论(0)
  • 2020-11-22 16:03

    If you followed Peter's answer and are still getting the same error, check to make sure anything else you have in your main function comes after the await Firebase.initializeApp() call, like so:

    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp();
      FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
      FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
      runApp(MyApp());
    }
    
    0 讨论(0)
  • 2020-11-22 16:03

    1st add this dependency:

    firebase_core :
    

    2nd: in the project main function add these 2 lines and make the function async

     void main() async {
      // these 2 lines
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp();
      //
      runApp(MyApp());
    }
    

    now you can use firebase normally in any file or widget in the project.

    FutureBuilder widget will work too but you must add it every time you want to access firebase.

    0 讨论(0)
提交回复
热议问题