Use English as fallback.

This commit is contained in:
Dain Nilsson 2023-03-01 10:57:42 +01:00
parent 4702666631
commit c8e84eb72d
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8

View File

@ -49,9 +49,17 @@ final l10nProvider = Provider<AppLocalizations>(
(ref) => ref.watch(_l10nProvider), (ref) => ref.watch(_l10nProvider),
); );
AppLocalizations _getL10n(Locale locale) {
try {
return lookupAppLocalizations(locale);
} catch (_) {
return lookupAppLocalizations(const Locale('en'));
}
}
class _L10nNotifier extends StateNotifier<AppLocalizations> class _L10nNotifier extends StateNotifier<AppLocalizations>
with WidgetsBindingObserver { with WidgetsBindingObserver {
_L10nNotifier() : super(lookupAppLocalizations(window.locale)) { _L10nNotifier() : super(_getL10n(window.locale)) {
WidgetsBinding.instance.addObserver(this); WidgetsBinding.instance.addObserver(this);
} }
@ -64,7 +72,7 @@ class _L10nNotifier extends StateNotifier<AppLocalizations>
@override @override
@protected @protected
void didChangeLocales(List<Locale>? locales) { void didChangeLocales(List<Locale>? locales) {
state = lookupAppLocalizations(window.locale); state = _getL10n(window.locale);
} }
} }