starter_architecture_flutter_firebase icon indicating copy to clipboard operation
starter_architecture_flutter_firebase copied to clipboard

Adding an extra step to show the customizable loading widget

Open ahmed-alhelali opened this issue 10 months ago • 1 comments

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: https://github.com/flutter/flutter/issues/6818

ahmed-alhelali avatar Apr 13 '24 08:04 ahmed-alhelali

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

realtec avatar Jun 02 '24 10:06 realtec