Skip to content

Commit 9274444

Browse files
committed
fix: fixed bug - if case before stopped AppearanceSettingModel to load locale
1 parent 39b0fe6 commit 9274444

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

frontend/app_flowy/lib/workspace/application/appearance.dart

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class AppearanceSettingModel extends ChangeNotifier with EquatableMixin {
1616

1717
AppearanceSettingModel(this.setting)
1818
: _theme = AppTheme.fromName(name: setting.theme),
19-
_locale = Locale(setting.locale.languageCode, setting.locale.countryCode);
19+
_locale =
20+
Locale(setting.locale.languageCode, setting.locale.countryCode);
2021

2122
AppTheme get theme => _theme;
2223
Locale get locale => _locale;
@@ -34,7 +35,8 @@ class AppearanceSettingModel extends ChangeNotifier with EquatableMixin {
3435
}
3536

3637
void swapTheme() {
37-
final themeType = (_theme.ty == ThemeType.light ? ThemeType.dark : ThemeType.light);
38+
final themeType =
39+
(_theme.ty == ThemeType.light ? ThemeType.dark : ThemeType.light);
3840

3941
if (_theme.ty != themeType) {
4042
_theme = AppTheme.fromType(themeType);
@@ -45,14 +47,15 @@ class AppearanceSettingModel extends ChangeNotifier with EquatableMixin {
4547
}
4648

4749
void setLocale(BuildContext context, Locale newLocale) {
48-
if (_locale != newLocale) {
49-
if (!context.supportedLocales.contains(newLocale)) {
50-
Log.warn("Unsupported locale: $newLocale");
51-
newLocale = const Locale('en');
52-
Log.debug("Fallback to locale: $newLocale");
53-
}
50+
if (!context.supportedLocales.contains(newLocale)) {
51+
Log.warn("Unsupported locale: $newLocale");
52+
newLocale = const Locale('en');
53+
Log.debug("Fallback to locale: $newLocale");
54+
}
55+
56+
context.setLocale(newLocale);
5457

55-
context.setLocale(newLocale);
58+
if (_locale != newLocale) {
5659
_locale = newLocale;
5760
setting.locale.languageCode = _locale.languageCode;
5861
setting.locale.countryCode = _locale.countryCode ?? "";
@@ -67,6 +70,10 @@ class AppearanceSettingModel extends ChangeNotifier with EquatableMixin {
6770
save();
6871

6972
setLocale(context, context.deviceLocale);
73+
return;
7074
}
75+
76+
// when opening app the first time
77+
setLocale(context, _locale);
7178
}
7279
}

0 commit comments

Comments
 (0)