We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
FlutterFire overview page is saying that "await Firebase.initializeApp();" is needed. (https://firebase.flutter.dev/docs/overview)
How should I can to do that is properly in stacked framework?
The text was updated successfully, but these errors were encountered:
I applied it as below.
import 'dart:async'; import 'package:firebase_core/firebase_core.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:injectable/injectable.dart'; import '../models/test_model.dart'; @singleton class FirestoreService { bool _initialized = false; // Define an async function to initialize FlutterFire Future<void> initializeFlutterFire() async { try { // Wait for Firebase to initialize and set `_initialized` state to true await Firebase.initializeApp(); _initialized = true; } catch (e) { // Set `_error` state to true if Firebase initialization fails print('error occured'); } } Future<CountryModel> getCountryData() async { if (!_initialized) { await initializeFlutterFire(); } CollectionReference example = FirebaseFirestore.instance.collection('example'); DocumentSnapshot doc = await country.doc('test').get(); return TestModel.fromJson(doc.data()); } }
It works! Is there any room for improvement or fixing?
Sorry, something went wrong.
You initialize in the main function
In your main.dart
void main(){ setupLocator(); await initializeFlutterFire(); runApp(child:MyApp()); }
No branches or pull requests
FlutterFire overview page is saying that "await Firebase.initializeApp();" is needed.
(https://firebase.flutter.dev/docs/overview)
How should I can to do that is properly in stacked framework?
The text was updated successfully, but these errors were encountered: