I have my flutter App integrated with firebase, everything was fine but when I migrated firebase project to client firebase console, added his google services file, changed DefaultFirebaseOption.currentplatform file credentials but I got error whenever I try to run my app. My main method looks like this:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
token = await FirebaseMessaging.instance.getToken();
Provider.debugCheckInvalidValueType = null;
runApp(const MyApp());
}
The error is:
E/flutter (28330): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: [core/duplicate-app] A Firebase App named "[DEFAULT]" already exists.
I searched here and found a solution from here and updated my main method like this:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
if (Firebase.apps.isNotEmpty) {
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
}else{
Firebase.app()
}
//await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
token = await FirebaseMessaging.instance.getToken();
Provider.debugCheckInvalidValueType = null;
runApp(const MyApp());
}
but this time I got no error but my app UI is not showing, I just see black screen. I have been trying to solve this from 4 to 5 hours but found no solution.any Help will highly be appreciated.
Update I provide name parameter in both of the scenrios and my app worked fine for first time i install, but when i retart or close app and re run it, I got same error as mentioned in above cases.