mirror of
https://github.com/git-touch/git-touch
synced 2025-02-02 08:56:54 +01:00
fix: set locale and reload
This commit is contained in:
parent
3f6955dd7f
commit
d488d4b826
@ -660,6 +660,11 @@ class AuthModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
var rootKey = UniqueKey();
|
||||
reloadApp() {
|
||||
rootKey = UniqueKey();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
setActiveAccountAndReload(int index) async {
|
||||
// https://stackoverflow.com/a/50116077
|
||||
rootKey = UniqueKey();
|
||||
|
@ -10,6 +10,7 @@ import 'package:primer/primer.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/locale.dart' as l;
|
||||
import 'package:flutter_gen/gen_l10n/S.dart';
|
||||
|
||||
class DialogOption<T> {
|
||||
final T value;
|
||||
@ -38,7 +39,8 @@ class SupportedLocales {
|
||||
'es': 'Español',
|
||||
'nb_NO': 'Norsk bokmål (Norge) ',
|
||||
'pt_BR': 'Portugues (brasil)',
|
||||
'zh_Hans': '简体中文'
|
||||
'zh_Hans': '简体中文',
|
||||
'zh_Hant': '正体中文'
|
||||
};
|
||||
}
|
||||
|
||||
@ -264,7 +266,7 @@ class ThemeModel with ChangeNotifier {
|
||||
_markdown = m;
|
||||
}
|
||||
final l = prefs.getString(StorageKeys.locale);
|
||||
if (SupportedLocales.values.contains(l)) {
|
||||
if (AppLocalizations.supportedLocales.any((v) => l == v.toString())) {
|
||||
_locale = l;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,16 @@ class SettingsScreen extends StatelessWidget {
|
||||
// return Icon(Icons.check, color: theme.palette.primary, size: 24);
|
||||
// }
|
||||
|
||||
// After translation finished, add locale name here to display in settings
|
||||
static const localeNameMap = {
|
||||
'en': 'English',
|
||||
'hi': 'हिन्दी',
|
||||
'es': 'Español',
|
||||
'nb_NO': 'Norsk bokmål (Norge)',
|
||||
'pt_BR': 'Portugues (brasil)',
|
||||
'zh_Hans': '简体中文',
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
@ -74,22 +84,32 @@ class SettingsScreen extends StatelessWidget {
|
||||
rightWidget: Text(auth.activeAccount.login),
|
||||
),
|
||||
TableViewItem(
|
||||
text: Text('App Language'),
|
||||
rightWidget: Text(SupportedLocales
|
||||
.languageNameExpanded[theme.locale ?? 'en']),
|
||||
onTap: () {
|
||||
theme.showActions(context, [
|
||||
for (var t in SupportedLocales.values)
|
||||
ActionItem(
|
||||
text: SupportedLocales.languageNameExpanded[t],
|
||||
onTap: (_) {
|
||||
if (theme.locale != t) {
|
||||
theme.setLocale(t);
|
||||
}
|
||||
},
|
||||
)
|
||||
]);
|
||||
})
|
||||
text: Text('App Language'),
|
||||
rightWidget: Text(theme.locale == null
|
||||
? AppLocalizations.of(context).followSystem
|
||||
: localeNameMap[theme.locale] ?? 'Unknown'),
|
||||
onTap: () {
|
||||
theme.showActions(context, [
|
||||
for (final e in [
|
||||
MapEntry(null, AppLocalizations.of(context).followSystem),
|
||||
...localeNameMap.entries
|
||||
])
|
||||
ActionItem(
|
||||
text: e.value,
|
||||
onTap: (_) async {
|
||||
final res = await theme.showConfirm(
|
||||
context,
|
||||
Text('Reload the App to take effect'),
|
||||
);
|
||||
if (res && theme.locale != e.key) {
|
||||
await theme.setLocale(e.key);
|
||||
auth.reloadApp();
|
||||
}
|
||||
},
|
||||
)
|
||||
]);
|
||||
},
|
||||
)
|
||||
]),
|
||||
CommonStyle.verticalGap,
|
||||
TableView(headerText: 'theme', items: [
|
||||
|
Loading…
x
Reference in New Issue
Block a user