1

In my project, I was using flutter 3.0.3. Once I updated to 3.0.4 and updated dependencies, suddenly when I launched the app on android, the splash screen is showing continuously(never going to the main app). I tried by moving to my previous commit, downgrading flutter but to no avail.

This happened before but I luckily fixed it by upgrading kotlin jdk to 8(was 7 before).

I am using flutter_native_splash library. But it looks it doesn't have any impact on my project.

This question talks about only release mode. But, in my case it is happening both release and debug modes. I would really appreciate your help on this!

My main function:

void mainCommon() {
  WidgetsFlutterBinding.ensureInitialized();

  SentryFlutter.init(
    (options) => options.dsn = Config.sentryDsn,
    appRunner: () async {
      await Firebase.initializeApp();
      await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
      final GlobalKey<ScaffoldMessengerState> messengerKey = GlobalKey<ScaffoldMessengerState>();
      await BlocOverrides.runZoned(
        () async => App(
          api: Api(Config.grpcChannel),
          database: await Config.db,
          appDirectory: await getApplicationDocumentsDirectory(),
          notificationManager: await NotificationManager.init(Config.grpcChannel),
          messengerKey: messengerKey,
        ),
        blocObserver: AppBlocObserver(errorCallback: BlocErrorHandler(messengerKey).errorCallback),
      );
    },
  );
}
Khamidjon Khamidov
  • 6,783
  • 6
  • 31
  • 62

1 Answers1

0

This is not for all cases. But, upgrading firebase_core and firebase_messaging could solve for some cases. In my case, it solved the problem for the first. But, once I upgraded all my other packages, it occurred again.

Android studio sucks. When I used Visual Studio Code, the exception was thrown in main where I initialised firebase. But in android, it ignored exception so I wasted a lot of time finding where the problem was.

To see the error in Android studio, you need to get mainCommon in try/catch bloc:

 try {
        await Firebase.initializeApp();
        await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
        runApp(App(
          api: Api(Config.grpcChannel),
          database: await Config.db,
          appDirectory: await getApplicationDocumentsDirectory(),
          notificationManager: await NotificationManager.init(Config.grpcChannel),
        ));
      } catch (e) {
        logger.e("Got exception in mainCommon: $e");
        rethrow;
      }
Khamidjon Khamidov
  • 6,783
  • 6
  • 31
  • 62