init method

Future<void> init()

Initializes this SettingsWorker and bootstraps the ApplicationSettings.locale, if needed.

Implementation

Future<void> init() async {
  String? locale = _settingsRepository.applicationSettings.value?.locale;
  if (locale == null) {
    _settingsRepository.setLocale(L10n.chosen.value!.toString());
  } else {
    await L10n.set(Language.fromTag(locale));
  }

  _worker = ever(_settingsRepository.applicationSettings, (
    ApplicationSettings? settings,
  ) {
    if (locale != settings?.locale) {
      locale = settings?.locale;
      L10n.set(Language.fromTag(locale) ?? L10n.languages.first);
      onChanged?.call(locale);
    }
  });
}