1

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.

Vasudev Soni
  • 43
  • 11
  • Do check out https://stackoverflow.com/q/71514802/11212287 – AkshayDoshi Nov 21 '22 at 14:33
  • I already checked this, it doesn't solves the issue. – Vasudev Soni Nov 21 '22 at 14:40
  • Try removing `FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler)` , `flutterLocalNotificationsPlugin` and `FirebaseMessaging.instance` methods from the `main()` method. Add those to the SplashScreen or your app's entry point – AkshayDoshi Nov 21 '22 at 14:47
  • There is no separate splash screen file as I used a package for that. And I am already implementing it in the entry point of my app which is the main() method right? – Vasudev Soni Nov 21 '22 at 14:51
  • By entry point I meant the first widget of the app. Try adding it in the initState of the first screen. – AkshayDoshi Nov 21 '22 at 14:55

0 Answers0