chore: don't set l1 if locale is not valid (#3654)
This commit is contained in:
parent
867004243f
commit
d1b7b13ab6
1 changed files with 6 additions and 2 deletions
|
|
@ -1,18 +1,22 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
|
||||
class LocaleProvider extends ChangeNotifier {
|
||||
Locale? _locale;
|
||||
|
||||
Locale? get locale => _locale;
|
||||
|
||||
void setLocale(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
final split = value?.split('_');
|
||||
if (split == null ||
|
||||
split.isEmpty ||
|
||||
!intl.DateFormat.localeExists(split[0])) {
|
||||
_locale = null;
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
|
||||
final split = value.split('-');
|
||||
_locale = Locale(split[0], split.length > 1 ? split[1] : null);
|
||||
notifyListeners();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue