appInitFirebase function
Future<FirebaseApp>
appInitFirebase(
- FirebaseOptions options
)
Implementation
Future<FirebaseApp> appInitFirebase(
FirebaseOptions options,
) async {
// Guard against a gate-retry re-run: `Firebase.initializeApp` throws
// `[core/duplicate-app]` on a second unconditional call. If the default app
// already exists, reuse it directly; otherwise initialize (Issue 17 /
// idempotency). The `duplicate-app` catch is a belt-and-suspenders fallback
// for the case where the platform layer has the default app registered while
// the Dart-side `Firebase.apps` cache is momentarily empty.
FirebaseApp fbApp;
if (Firebase.apps.isNotEmpty) {
fbApp = Firebase.app();
} else {
try {
fbApp = await Firebase.initializeApp(
// options: DefaultFirebaseOptions.currentPlatform,
options: options,
);
} on FirebaseException catch (e) {
if (e.code.contains('duplicate-app')) {
fbApp = Firebase.app();
} else {
rethrow;
}
}
}
// Mark Firebase as initialized and store the app reference for the rest of the package
AppConfigBase.isFirebaseInitialized = true;
AppConfigBase.firebaseApp = fbApp;
return fbApp;
}