Исправлено переключение локали на экране сканера

This commit is contained in:
Ivan Murashov
2017-09-21 13:09:38 +03:00
parent eba8c9e642
commit afc9cde20d
12 changed files with 85 additions and 49 deletions

View File

@@ -40,19 +40,23 @@ class LanguagesState extends SettingsBaseState<LanguagesScreen> {
saveOption() async {
await helper.saveLocale(languages[selectedItem]);
Intl.defaultLocale = languages[selectedItem];
StringsLocalization.load(languages[selectedItem]).then((_) {
setState(() {
});
});
await StringsLocalization.load(languages[selectedItem]);
}
@override
void getSelectedValue() {
helper.getLocale().then((locale) {
setState(() {
selectedItem = getOptions().indexOf(getLocaleTitle(locale));
});
if (locale == null) {
platform.invokeMethod('getLocale').then((locale) {
setState(() {
selectedItem == locale;
});
});
} else {
setState(() {
selectedItem = getOptions().indexOf(getLocaleTitle(locale));
});
}
});
}
}

View File

@@ -7,6 +7,7 @@ import 'package:checker/screens/currencies.dart';
import 'package:checker/screens/languages.dart';
import 'package:checker/strings.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class SettingsScreen extends BaseScreen {
@@ -28,8 +29,8 @@ class MenuItem {
class SettingsState extends BaseState<SettingsScreen> {
List<MenuItem> menuItems = [
new MenuItem(StringsLocalization.currency(), ''),
new MenuItem(StringsLocalization.locale(), '')
new MenuItem('', ''),
new MenuItem('', '')
];
bool returnToScanner;
@@ -42,23 +43,24 @@ class SettingsState extends BaseState<SettingsScreen> {
@override Widget build(BuildContext ctx) {
helper.getSettings().then((info) {
if (menuItems != null) {
if (menuItems[0].selectedValue != info['currency'].toString()) {
setState(() {
menuItems[0].selectedValue = info['currency'].toString();
menuItems[1].selectedValue = info['locale'].toString();
});
}
}
setState(() {
menuItems[0].title = StringsLocalization.currency();
menuItems[1].title = StringsLocalization.locale();
menuItems[0].selectedValue = info['currency'].toString();
menuItems[1].selectedValue = info['locale'] == null ? Intl.defaultLocale : info['locale'].toString();
});
});
return new WillPopScope(onWillPop: onWillPop, child: getMainWidget());
}
Widget getMainWidget() {
return new Scaffold(appBar: getAppBar(),
body: getScreenContent());
}
@override
Widget getScreenContent() {
return menuItems == null
? getBackground()
: new Container(
return new Container(
margin: new EdgeInsets.only(top: 16.0),
child: new ListView(children: getSettings()));
}

View File

@@ -38,24 +38,43 @@ class _SplashScreenState extends BaseState<SplashScreen> {
}
void onStart() {
helper.getSettings().then((info) {
if (info == null) {
platform.invokeMethod('getCurrency').then((currency) {
platform.invokeMethod('getLocale').then((locale) {
initLocale(locale, () {
helper.createAppInfo(locale, currency).then((_) {
showNext();
});
});
});
});
helper.getLocale().then((locale) {
if (locale == null) {
initWithSystemValue();
} else {
helper.getLocale().then((locale) {
initWithSavedValue();
}
});
}
void initWithSystemValue() {
platform.invokeMethod('getLocale').then((locale) {
helper.getSettings().then((settings) {
if (settings == null) {
createSettingsTable(locale);
} else {
initLocale(locale, () {
showNext();
});
});
}
}
});
});
}
void initWithSavedValue() {
helper.getLocale().then((locale) {
initLocale(locale, () {
showNext();
});
});
}
void createSettingsTable(String locale) {
platform.invokeMethod('getCurrency').then((currency) {
helper.createAppInfo(locale, currency);
initLocale(locale, () {
showNext();
});
});
}