Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an extra step to show the customizable loading widget #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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