starter_architecture_flutter_firebase
starter_architecture_flutter_firebase copied to clipboard
Adding an extra step to show the customizable loading widget
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
Nice approach, but this way you won't be able to retry when the initialisation fails