Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Unhandled Exception: [core/duplicate-app]

I am building a flutter app with firebase. The firebase services I am using are Realtime database and Authentication. The app is normally starting as usual without throwing any exception, but while I am hot restarting the app, the app freezes throwing the following exception:

Unhandled Exception: [core/duplicate-app] A Firebase App named "db2" already exists

I believe there's something wrong with initializing FirebaseApp. The initialization code in main.dart reads:

WidgetsFlutterBinding.ensureInitialized();
  final FirebaseApp app = await Firebase.initializeApp(
    name: 'db2',

Can somebody help me solve this issue? Thank you!

like image 437
Amit Kumar Yadav Avatar asked Aug 23 '26 16:08

Amit Kumar Yadav


1 Answers

I have two apps in firebase.One is Android and another one is web . So Initialize firebase instance like this

const firebaseConfig = FirebaseOptions(
apiKey: "AIzaSyA1S7r-kyTOCLWttcf4kC3Qye0s-gl96Ec",
appId: "1:390108250565:web:9821516ca39ba976358bac",
messagingSenderId: "390108250565",
projectId: "doc-appointment-aa751",
);


if(kIsWeb){

 await Firebase.initializeApp(
   options: firebaseConfig,
 );
}else{
   await Firebase.initializeApp();
} 
like image 62
Saddan Avatar answered Aug 26 '26 22:08

Saddan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!