initialize static method

Future<void> initialize({
  1. required BuildContext context,
  2. ProKitThemeModel? customLightTheme,
  3. ProKitThemeModel? customDarkTheme,
})

Implementation

static Future<void> initialize({
  required BuildContext context, /// Make BuildContext non-nullable
  ProKitThemeModel? customLightTheme,
  ProKitThemeModel? customDarkTheme,
}) async {
  /// Initialize Size Config
  if (context.mounted) {
    SizeConfig.init(context);
  } else {
    debugPrint("Context is not mounted, skipping SizeConfig initialization.");
  }

  /// Initialize Shared Preferences and then Theme
  try {
    await ProKitPrefManager.initialize();

    if (context.mounted) {
      /// Initialize providers and other app-level states
      ProKitProviderAccess.init(context);

      /// Initialize the app theme (light and dark)
      ProKitTheme.initialize(
        customLightTheme: customLightTheme!,
        customDarkTheme: customDarkTheme!,
      );

      /// Initialize theme based on preferences
      if (ProKitNavigator.navigatorKey.currentContext != null) {
        ProKitThemeProvider.state(ProKitNavigator.navigatorKey.currentContext!)
            .initializeTheme();
      } else {
        debugPrint("Navigator key's current context is null.");
      }
    }
  } catch (e) {
    /// Handle any potential errors during initialization
    debugPrint("Error initializing ProKit: $e");
  }
}