1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-02 08:56:54 +01:00

fix: set locale null

This commit is contained in:
Rongjian Zhang 2021-05-31 00:08:38 +08:00
parent e2f103a807
commit 9b3a6fce07
2 changed files with 10 additions and 6 deletions

View File

@ -166,10 +166,14 @@ class ThemeModel with ChangeNotifier {
String? _locale;
String? get locale => _locale;
Future<void> setLocale(String v) async {
Future<void> setLocale(String? v) async {
_locale = v;
final prefs = await SharedPreferences.getInstance();
await prefs.setString(StorageKeys.locale, v);
if (v == null) {
await prefs.remove(StorageKeys.locale);
} else {
await prefs.setString(StorageKeys.locale, v);
}
notifyListeners();
}

View File

@ -86,13 +86,13 @@ class SettingsScreen extends StatelessWidget {
? AppLocalizations.of(context)!.followSystem
: localeNameMap[key],
onTap: (_) async {
final res = await (theme.showConfirm(
final res = await theme.showConfirm(
context,
Text(
'The app will reload to make the language setting take effect'),
) as Future<bool>);
if (res && theme.locale != key) {
await theme.setLocale(key!);
);
if (res == true && theme.locale != key) {
await theme.setLocale(key);
auth.reloadApp();
}
},