initialize method

Future<void> initialize()

Initializes the controller by reading the saved language from SharedPreferences. Falls back to the system locale when nothing has been saved. Safe to call multiple times.

Implementation

Future<void> initialize() async {
  if (_initialized) return;

  final prefs = await SharedPreferences.getInstance();
  final savedCode = prefs.getString(_prefsKey);
  final targetCode = savedCode ?? _resolveSystemLocale();
  final lang = DocumentLanguage.fromCode(targetCode);
  if (currentLanguage.value.code != lang.code) {
    currentLanguage.value = lang;
  }
  _initialized = true;
}