init method

Future<void> init()

Loads persisted values from SharedPreferences.

Call once at app startup after WidgetsFlutterBinding.ensureInitialized. If no saved values exist, the defaults passed to the constructor are kept.

Implementation

Future<void> init() async {
  final prefs = await SharedPreferences.getInstance();

  final modeIndex = prefs.getInt(_kThemeModeKey);
  if (modeIndex != null && modeIndex < ThemeMode.values.length) {
    _themeMode = ThemeMode.values[modeIndex];
  }

  final brandIndex = prefs.getInt(_kBrandKey);
  if (brandIndex != null && brandIndex < DsBrand.values.length) {
    _brand = DsBrand.values[brandIndex];
  }

  final localeCode = prefs.getString(_kLocaleKey);
  if (localeCode != null && localeCode.isNotEmpty) {
    _locale = Locale(localeCode);
  }

  notifyListeners();
}