build method

  1. @override
Locale build()
override

Initialize a Notifier.

It is safe to use Ref.watch or Ref.listen inside this method.

If a dependency of this Notifier (when using Ref.watch) changes, then build will be re-executed. On the other hand, the Notifier will not be recreated. Its instance will be preserved between executions of build.

If this method throws, reading this provider will rethrow the error.

Implementation

@override
Locale build() {
  final savedLocaleCode = JetStorage.read<String>(_localeStorageKey);
  if (savedLocaleCode != null) {
    final locale = Locale(savedLocaleCode);
    final config = ref.read(jetProvider).config;
    if (config.supportedLocales.any(
      (supported) => supported.locale.languageCode == locale.languageCode,
    )) {
      return locale;
    }
  }
  return const Locale('en');
}