Skip to content

Conversation

@ahmed-alhelali
Copy link

By calling the runApp twice we can show our custom loading widget while the app is being initialized in the `main' with the benefits of supporting Deep Links as:

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  
  runApp(
    const MaterialApp(
        home: AppStartupLoadingWidget(),
    ),
  );

  
  // turn off the # in the URLs on the web
  usePathUrlStrategy();
  // * Register error handlers. For more info, see:
  // * https://docs.flutter.dev/testing/errors
  registerErrorHandlers();
  // * Initialize Firebase
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
  // * Entry point of the app
  runApp(const ProviderScope(
    child: MyApp(),
  ));
}

And according to Flutter documentation, it says

/// Calling [runApp] again will detach the previous root widget from the screen
/// and attach the given widget in its place. The new widget tree is compared
/// against the previous widget tree and any differences are applied to the
/// underlying render tree, similar to what happens when a [StatefulWidget]
/// rebuilds after calling [State.setState].

credits to: flutter/flutter#6818

@realtec
Copy link

realtec commented Jun 2, 2024

Nice approach, but this way you won't be able to retry when the initialisation fails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants