read device locale as default locale setting

This commit is contained in:
appflowy 2022-02-01 09:12:59 +08:00
parent 8127e47cea
commit be806e301c
4 changed files with 22 additions and 3 deletions

View File

@ -59,6 +59,7 @@ class ApplicationWidget extends StatelessWidget {
const ratio = 1.73;
const minWidth = 600.0;
setWindowMinSize(const Size(minWidth, minWidth / ratio));
settingModel.updateWithBuildContext(context);
AppTheme theme = context.select<AppearanceSettingModel, AppTheme>(
(value) => value.theme,
);

View File

@ -39,7 +39,7 @@ class AppearanceSettingModel extends ChangeNotifier with EquatableMixin {
}
void setLanguage(BuildContext context, AppLanguage language) {
String languageString = stringFromLanguageName(language);
String languageString = stringFromLanguage(language);
if (setting.language != languageString) {
context.setLocale(localeFromLanguageName(language));
@ -49,4 +49,9 @@ class AppearanceSettingModel extends ChangeNotifier with EquatableMixin {
save();
}
}
void updateWithBuildContext(BuildContext context) {
final language = languageFromLocale(context.deviceLocale);
setLanguage(context, language);
}
}

View File

@ -7,7 +7,7 @@ enum AppLanguage {
french,
}
String stringFromLanguageName(AppLanguage language) {
String stringFromLanguage(AppLanguage language) {
switch (language) {
case AppLanguage.english:
return "en";
@ -45,3 +45,16 @@ Locale localeFromLanguageName(AppLanguage language) {
return const Locale('fr', 'CA');
}
}
AppLanguage languageFromLocale(Locale locale) {
switch (locale.languageCode) {
case "zh":
return AppLanguage.chinese;
case "it":
return AppLanguage.italian;
case "fr":
return AppLanguage.french;
default:
return AppLanguage.english;
}
}

View File

@ -694,7 +694,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
version: "0.1.3"
meta:
dependency: transitive
description: