main function
Implementation
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// init firebase once (with the generated options for web/mobile)
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
// any other async initializations
await SharedPreferencesGlobal().initialize();
// Pass all uncaught framework errors to Crashlytics
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
// Pass uncaught async/native errors to Crashlytics
PlatformDispatcher.instance.onError = (Object error, StackTrace stack) {
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
return true;
};
errorScreen();
// runZonedGuarded catches async errors that happen outside the Flutter framework
runZonedGuarded<Future<void>>(
() async {
final localeCubit = await LocaleCubit.create();
final updateCubit = UpdateCubit()..checkForUpdate();
final themeCubit = ThemeCubit(
themeSharedPreferences: ThemeSharedPreferences(),
);
runApp(
MultiBlocProvider(
providers: [
// using .value is fine because we already created the instances above.
BlocProvider<ThemeCubit>.value(value: themeCubit),
BlocProvider<LocaleCubit>.value(value: localeCubit),
BlocProvider<UpdateCubit>.value(value: updateCubit),
],
child: kIsWeb
? TakyeebbakWeb(appRouter: AppRouter())
: TakyeebBakApp(appRouter: AppRouter()),
),
);
},
(Object error, StackTrace stack) {
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
},
);
}