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

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

@@ -14,15 +14,13 @@ abstract class SettingsBaseState<T extends StatefulWidget> extends BaseState<T>
int selectedItem;
@override Widget build(BuildContext context) {
return getMainWidget();
return new Scaffold(appBar: getAppBar(),
body: getScreenContent());
}
@override
Widget getScreenContent() {
getSelectedValue();
List<Widget> widgets = new List();
for (String option in getOptions()) {

View File

@@ -87,6 +87,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
});
} else {
String token = await helper.getToken();
String locale = await helper.getLocale();
helper.close();
// Канал ловит вызовы методов из "нативной" части приложения.
// Могут быть вызваны либо logout либо faq, либо purchase.
@@ -119,6 +120,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
'token': token,
'url': url,
'appToken': appToken,
'locale': locale,
'color': Resources
.getPrimaryColor(app)
.value

View File

@@ -3,11 +3,11 @@ import 'package:flutter/material.dart';
// Serious constants
const String appName = "Autobonus";
//const String url = 'https://pos-api-autoclub.dinect.com/20130701/';
//const String appToken = 'bdea0f3ba9034b688019a7cac753d1209e2b227f';
const String url = 'https://pos-api-autoclub.dinect.com/20130701/';
const String appToken = 'bdea0f3ba9034b688019a7cac753d1209e2b227f';
const String url = 'https://pos-api-int.dinect.com/20130701/';
const String appToken = '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';
//const String url = 'https://pos-api-int.dinect.com/20130701/';
//const String appToken = '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';
// Assets
const String logout_png = 'assets/logout.png';

View File

@@ -70,7 +70,6 @@ class SqliteHelper {
return null;
} else {
return db.insert(tableSettings, {
columnLocale: locale,
columnCurrency: currency
});
}

View File

@@ -77,7 +77,7 @@ class MessageLookup extends MessageLookupByLibrary {
"usage_guide": MessageLookupByLibrary.simpleMessage('''
Шаг 1:
Запустите прилодение для сканирования карты участника системы лояльности.
Запустите приложение для сканирования карты участника системы лояльности.
При успешном сканировании на вашем экране появятся данные покупателя.

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();
});
});
}