Skip to content

Commit

Permalink
fix: set locale null
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed May 30, 2021
1 parent e2f103a commit 9b3a6fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/models/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
8 changes: 4 additions & 4 deletions lib/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
},
Expand Down

0 comments on commit 9b3a6fc

Please sign in to comment.