We have a Flutter app launched in both stores. The app that we have has a terrible launching/starting time and is taking too much time. People are generally stuck on the black screen (They cannot reach the splash screen view that we showing a video) or waiting several seconds until the splash view.
Before we run the app, MyApp
or MainApp
, we are instantiating lots of libraries such as FlutterSecureStorage, Firebase, Hive & Hive's DBs
.
I am open to any suggestion to encounter the problem that we are having.
// one part of the main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
lockOrientation();
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarBrightness: Brightness.dark,
systemNavigationBarColor: AppColors.transparent,
),
);
storage = const FlutterSecureStorage(
iOptions: IOSOptions(accessibility: KeychainAccessibility.first_unlock),
aOptions: AndroidOptions(encryptedSharedPreferences: true),
);
await Firebase.initializeApp();
await Future.wait(
[
setupInjector(),
setupLocator(),
Hive.initFlutter(),
],
);
// Initializing some hive services to pass Riverpod's provider
await initModels();
final services = await initDbServices();
final downloadServices = await initDownloadDbServices();
await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(!kDebugMode);
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
Isolate.current.addErrorListener(RawReceivePort((pair) async {
final List<dynamic> errorAndStacktrace = pair;
await FirebaseCrashlytics.instance.recordError(
errorAndStacktrace.first,
errorAndStacktrace.last,
);
}).sendPort);
Platform.isIOS
? InAppPurchaseStoreKitPlatform.registerPlatform()
: !DeviceInfo.isHarmonyOS
? InAppPurchaseAndroidPlatform.registerPlatform()
: null;
RemoteConfigSettings setting =
RemoteConfigSettings(minimumFetchInterval: const Duration(hours: 1), fetchTimeout: const Duration(minutes: 1));
await remoteConfig.setConfigSettings(setting);
NotificationService.instance.listenPushNotifications?.listen((uri) => deeplinkUri = URI);
return runZonedGuarded(
() => ProviderScope(child: runApp(MyApp())),
FirebaseCrashlytics.instance.recordError,
);
}