Fix Firebase initialization error - no-app exception
- Add Firebase.initializeApp() call in mainCommon.dart before any Firebase-dependent code - Make mainCommon() async to support await Firebase.initializeApp() - Update mainDev.dart to properly await mainCommon() call - Add android:enableOnBackInvokedCallback='true' to AndroidManifest.xml to fix OnBackInvokedCallback warning This resolves the 'No Firebase App [DEFAULT] has been created' error that was occurring when firebase_messaging tried to access FirebaseMessaging.instance in homePage.dart. Firebase must be initialized before any Firebase APIs are used.
This commit is contained in:
parent
13c6ff90f5
commit
fa8c388f07
2 changed files with 7 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
|
@ -27,8 +28,12 @@ Future<Map<String, dynamic>> loadSecrets() async {
|
|||
.load();
|
||||
}
|
||||
|
||||
void mainCommon(List<Middleware<AppState>> otherMiddleware) {
|
||||
Future<void> mainCommon(List<Middleware<AppState>> otherMiddleware) async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Initialize Firebase before any Firebase-dependent code runs
|
||||
await Firebase.initializeApp();
|
||||
|
||||
final getIt = GetIt.instance;
|
||||
getIt.registerSingleton<FiresApi>(FiresApi());
|
||||
loadPackageInfo().then((packageInfo) {
|
||||
|
|
|
|||
|
|
@ -24,5 +24,5 @@ void main() async {
|
|||
logRedux == LogLevel.actions ? [] : [createLoggingMiddleware()];
|
||||
|
||||
// In development, Sentry is disabled, so we skip initialization
|
||||
mainCommon(devMiddlewares);
|
||||
await mainCommon(devMiddlewares);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue