Here is my code -
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(_) async {
await Firebase.initializeApp();
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseAppCheck.instance.activate(
androidProvider: AndroidProvider.playIntegrity,
);
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) => MainProvider(),
),
ChangeNotifierProvider(
create: (_) => SellerFormProvider(),
),
ChangeNotifierProvider(
create: (_) => LocationProvider(),
),
],
child: const MyApp(),
),
);
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
And here is the console log errors -
W/FlutterJNI(32413): FlutterJNI.loadLibrary called more than once
W/FlutterJNI(32413): FlutterJNI.prefetchDefaultFontManager called more than once
I/ResourceExtractor(32413): Found extracted resources res_timestamp-6-1669032211535
W/FlutterJNI(32413): FlutterJNI.init called more than once
I/FLTFireBGExecutor(32413): Creating background FlutterEngine instance.
W/DartExecutor(32413): Attempted to run a DartExecutor that is already running.
Please help me with this issue. I think the error is occuring because we are calling Firebase.initializeApp() twice in the code. But I am not able to understand how to remove the error.