diff --git a/lib/common.dart b/lib/common.dart index 5a078b8..413099c 100644 --- a/lib/common.dart +++ b/lib/common.dart @@ -14,15 +14,19 @@ import 'strings.dart'; const platform = const MethodChannel('com.dinect.checker/instance_id'); // Метод обеспечивает замену текущего объекта route новым. -pushRoute(BuildContext context, Widget widget) { +pushRouteReplacement(BuildContext context, Widget widget) { var route = new MaterialPageRoute(builder: (BuildContext context) => widget); Navigator.of(context).pushReplacement(route); } +pushRoute(BuildContext context, Widget widget) { + var route = new MaterialPageRoute(builder: (BuildContext context) => widget); + Navigator.of(context).push(route); +} + // Добавление route, с возможностью вернуться к предыдущему экрану. faq(BuildContext context, bool returnToScanner) { - var route = new MaterialPageRoute(builder: (BuildContext context) => new FAQScreen(returnToScanner)); - Navigator.of(context).push(route); + pushRoute(context, new FAQScreen(returnToScanner)); } // В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения. @@ -32,14 +36,14 @@ logout(BuildContext context) async { await helper.open(); String token = await helper.getToken(); - VoidCallback positiveCalback = () { + VoidCallback positiveCallback = () { if (token != null) { deleteToken(token).then((response) { print(response.body); platform.invokeMethod('removeKeys').then((result) { Navigator.of(context).pop(); Navigator.of(context).pop(); - pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию + pushRouteReplacement(context, new RegistrationScreen()); // Запускаем регистрацию }); }).catchError((error) { print(error.toString()); @@ -50,7 +54,7 @@ logout(BuildContext context) async { } }; - showYesNoDialog(context, StringsLocalization.confirmation(), StringsLocalization.askChangeStore(), positiveCalback); + showYesNoDialog(context, StringsLocalization.confirmation(), StringsLocalization.askChangeStore(), positiveCallback); } forceLogout(String token , BuildContext context) async { @@ -62,7 +66,7 @@ forceLogout(String token , BuildContext context) async { helper.clear().then((_) { helper.close().then((_) { Navigator.of(context).pop(); - pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию + pushRouteReplacement(context, new RegistrationScreen()); // Запускаем регистрацию }); }); }); @@ -122,3 +126,19 @@ showYesNoDialog(BuildContext context, String title, String content, VoidCallback child: new Text(StringsLocalization.yes()), onPressed: positiveCallback)])); } + +getCurrencyTitle(int code) { + switch(code) { + case 643: return StringsLocalization.ruble(); + case 840: return StringsLocalization.dollar(); + case 980: return StringsLocalization.hryvna(); + } +} + +getLocaleTitle(String code) { + switch(code) { + case 'ru': return StringsLocalization.russian(); + case 'en': return StringsLocalization.english(); + case 'ua': return StringsLocalization.ukrainian(); + } +} \ No newline at end of file diff --git a/lib/db.dart b/lib/db.dart index cb864d1..9dfe716 100644 --- a/lib/db.dart +++ b/lib/db.dart @@ -90,7 +90,7 @@ class SqliteHelper { Future getMerchantID() async { Map session = await selectAll(tableSession); String merchantID = session != null ? session[columnMerchantID] : null; - print('token: {$merchantID}'); + print('merchantID: {$merchantID}'); return merchantID; } @@ -107,6 +107,20 @@ class SqliteHelper { return docID; } + Future getLocale() async { + Map settings = await selectAll(tableSettings); + String locale = settings != null ? settings[columnLocale] : null; + print('locale: {$locale}'); + return locale; + } + + Future getCurrency() async { + Map settings = await selectAll(tableSettings); + String currency = settings != null ? settings[columnCurrency] : null; + print('currency: {$currency}'); + return currency; + } + Future selectAll(String table) async { List maps = await db.query(table, columns: null); diff --git a/lib/i18n/messages_en.dart b/lib/i18n/messages_en.dart index c5a0503..f198955 100644 --- a/lib/i18n/messages_en.dart +++ b/lib/i18n/messages_en.dart @@ -43,6 +43,13 @@ class MessageLookup extends MessageLookupByLibrary { "help " : MessageLookupByLibrary.simpleMessage("FAQ"), "logout" : MessageLookupByLibrary.simpleMessage("Logout"), "currency" : MessageLookupByLibrary.simpleMessage("Currency"), - "locale" : MessageLookupByLibrary.simpleMessage("Locale") + "locale" : MessageLookupByLibrary.simpleMessage("Locale"), + "russian" : MessageLookupByLibrary.simpleMessage("Russian"), + "english" : MessageLookupByLibrary.simpleMessage("English"), + "ukrainian" : MessageLookupByLibrary.simpleMessage("Ukrainian"), + "rubles" : MessageLookupByLibrary.simpleMessage("Ruble"), + "dollars" : MessageLookupByLibrary.simpleMessage("Dollar"), + "hryvna" : MessageLookupByLibrary.simpleMessage("Hryvna") + }; } diff --git a/lib/i18n/messages_es.dart b/lib/i18n/messages_es.dart index 0faa5d9..f6b8f47 100644 --- a/lib/i18n/messages_es.dart +++ b/lib/i18n/messages_es.dart @@ -38,6 +38,15 @@ class MessageLookup extends MessageLookupByLibrary { "sum" : MessageLookupByLibrary.simpleMessage("Suma"), "update_activ_status" : MessageLookupByLibrary.simpleMessage("Actualizar la condición de activación"), "user_name" : MessageLookupByLibrary.simpleMessage("Un nombre de usario"), - "yes" : MessageLookupByLibrary.simpleMessage("Si") + "yes" : MessageLookupByLibrary.simpleMessage("Si"), + "logout" : MessageLookupByLibrary.simpleMessage("Logout"), + "currency" : MessageLookupByLibrary.simpleMessage("Currency"), + "locale" : MessageLookupByLibrary.simpleMessage("Locale"), + "russian" : MessageLookupByLibrary.simpleMessage("Russian"), + "english" : MessageLookupByLibrary.simpleMessage("English"), + "ukrainian" : MessageLookupByLibrary.simpleMessage("Ukrainian"), + "rubles" : MessageLookupByLibrary.simpleMessage("Ruble"), + "dollars" : MessageLookupByLibrary.simpleMessage("Dollar"), + "hryvna" : MessageLookupByLibrary.simpleMessage("Hryvna") }; } diff --git a/lib/i18n/messages_ru.dart b/lib/i18n/messages_ru.dart index 0b2733a..10b0b0c 100644 --- a/lib/i18n/messages_ru.dart +++ b/lib/i18n/messages_ru.dart @@ -43,6 +43,12 @@ class MessageLookup extends MessageLookupByLibrary { "help " : MessageLookupByLibrary.simpleMessage("Справка"), "logout" : MessageLookupByLibrary.simpleMessage("Выход"), "currency" : MessageLookupByLibrary.simpleMessage("Валюта"), - "locale" : MessageLookupByLibrary.simpleMessage("Язык") + "locale" : MessageLookupByLibrary.simpleMessage("Язык"), + "russian" : MessageLookupByLibrary.simpleMessage("Русский"), + "english" : MessageLookupByLibrary.simpleMessage("Английский"), + "ukrainian" : MessageLookupByLibrary.simpleMessage("Украинский"), + "rubles" : MessageLookupByLibrary.simpleMessage("Рубль"), + "dollars" : MessageLookupByLibrary.simpleMessage("Доллар"), + "hryvna" : MessageLookupByLibrary.simpleMessage("Гривна") }; } diff --git a/lib/i18n/messages_ua.dart b/lib/i18n/messages_ua.dart index ac058c6..9baa6bf 100644 --- a/lib/i18n/messages_ua.dart +++ b/lib/i18n/messages_ua.dart @@ -38,6 +38,15 @@ class MessageLookup extends MessageLookupByLibrary { "sum" : MessageLookupByLibrary.simpleMessage("Сума"), "update_activ_status" : MessageLookupByLibrary.simpleMessage("Оновити статус активації"), "user_name" : MessageLookupByLibrary.simpleMessage("ПІБ"), - "yes" : MessageLookupByLibrary.simpleMessage("Так") + "yes" : MessageLookupByLibrary.simpleMessage("Так"), + "logout" : MessageLookupByLibrary.simpleMessage("Logout"), + "currency" : MessageLookupByLibrary.simpleMessage("Currency"), + "locale" : MessageLookupByLibrary.simpleMessage("Locale"), + "russian" : MessageLookupByLibrary.simpleMessage("Russian"), + "english" : MessageLookupByLibrary.simpleMessage("English"), + "ukrainian" : MessageLookupByLibrary.simpleMessage("Ukrainian"), + "rubles" : MessageLookupByLibrary.simpleMessage("Ruble"), + "dollars" : MessageLookupByLibrary.simpleMessage("Dollar"), + "hryvna" : MessageLookupByLibrary.simpleMessage("Hryvna") }; } diff --git a/lib/main.dart b/lib/main.dart index a9da1c9..8b6e94d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,20 +5,6 @@ import 'strings.dart'; import 'common.dart'; import 'dart:async'; -class StringsLocalizationDelegate extends LocalizationsDelegate { - - @override - Future load(Locale locale) async { - return StringsLocalization.load(await platform.invokeMethod("getLocale")); - } - - @override - bool shouldReload(LocalizationsDelegate old) { - return false; - } - -} - /// Точка входа в приложение. void main() { runApp(new Checker()); @@ -33,12 +19,7 @@ class CheckerState extends State { @override Widget build(BuildContext context) { return new MaterialApp( title: appName, - home: new SplashScreen(), - localizationsDelegates: getLocalizationsDelegate() - ); + home: new SplashScreen()); } - getLocalizationsDelegate() { - return [new StringsLocalizationDelegate()]; - } } diff --git a/lib/screens/purchase.dart b/lib/screens/purchase.dart index dd2d915..1022563 100644 --- a/lib/screens/purchase.dart +++ b/lib/screens/purchase.dart @@ -220,7 +220,7 @@ class PurchaseScreenState extends BaseState { print(response.body); helper.close().then((_) { Navigator.of(context).pop(); - pushRoute(context, new PurchaseSuccessScreen(sumTotal, user['first_name'] == null ? '' : user['first_name'])); + pushRouteReplacement(context, new PurchaseSuccessScreen(sumTotal, user['first_name'] == null ? '' : user['first_name'])); }); }).catchError((error) { diff --git a/lib/screens/registration.dart b/lib/screens/registration.dart index 3b56c09..0f19ff6 100644 --- a/lib/screens/registration.dart +++ b/lib/screens/registration.dart @@ -87,7 +87,7 @@ class _RegistrationScreenState extends BaseState { if (response.statusCode == 201) { helper.createSession(dinCode, posID, parsedMap['token']).then((_) { helper.close(); - pushRoute(context, new FinishRegistrationScreen()); + pushRouteReplacement(context, new FinishRegistrationScreen()); }); } else { setState(() { diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index a7f1a43..edc01f5 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -17,10 +17,10 @@ class SettingsScreen extends StatefulWidget { class MenuItem { - MenuItem(); + // Заголовок пункта меню и выбранное значение. + String title, selectedValue; - String title; - String selectedValue; + MenuItem(this.title, this.selectedValue); } class _SettingsState extends BaseState { @@ -31,16 +31,11 @@ class _SettingsState extends BaseState { if (menuItems == null) { helper.getSettings().then((info) { setState(() { - print("load settings"); - - menuItems = [new MenuItem(), new MenuItem()]; - - menuItems[0].title = StringsLocalization.locale(); - menuItems[0].selectedValue = info["locale"]; - - menuItems[1].title = StringsLocalization.currency(); - menuItems[1].selectedValue = info["currency"].toString(); + menuItems = [ + new MenuItem(StringsLocalization.locale(), getLocaleTitle(info["locale"])), + new MenuItem(StringsLocalization.currency(), getCurrencyTitle(info["currency"])) + ]; }); }); } @@ -53,17 +48,35 @@ class _SettingsState extends BaseState { : new ListView(children: getSettings()); } + @override + List getMenuButtons() { + return null; + } + List getSettings() { List widgets = new List(); for (MenuItem item in menuItems) { - widgets.add(new Row(children: [ - new Text(item.title, textAlign: TextAlign.left), - new Text(item.selectedValue,textAlign: TextAlign.right), - new Image.asset(settings_arrow_png, width: 28.0, height: 28.0, alignment: FractionalOffset.centerRight)])); + widgets.add(getSettingsItem(item)); } return widgets; } + Widget getSettingsItem(MenuItem item) { + return new Container( + margin: const EdgeInsets.all(16.0), + child: new Row(children: [ + new Expanded(child: new Text(item.title)), + new Text(item.selectedValue), + getArrow()]) + ); + } + + Widget getArrow() { + return new Image.asset(settings_arrow_png, + width: 28.0, + height: 28.0); + } + @override String getTitle() { return StringsLocalization.settings(); diff --git a/lib/screens/splash.dart b/lib/screens/splash.dart index 28eab62..2109f9a 100644 --- a/lib/screens/splash.dart +++ b/lib/screens/splash.dart @@ -1,3 +1,4 @@ +import 'package:checker/strings.dart'; import 'package:flutter/material.dart'; import 'package:http/http.dart'; import 'package:intl/intl.dart'; @@ -26,7 +27,6 @@ class _SplashScreenState extends BaseState { helper.getSettings().then((info) { if (info == null) { platform.invokeMethod('getLocale').then((locale) { - Intl.defaultLocale = locale; platform.invokeMethod('getCurrency').then((currency) { helper.createAppInfo(locale, currency).then((_) { showNext(); @@ -34,7 +34,12 @@ class _SplashScreenState extends BaseState { }); }); } else { - showNext(); + helper.getLocale().then((locale) { + Intl.defaultLocale = locale; + StringsLocalization.load(locale).then((l) { + showNext(); + }); + }); } }); } @@ -90,7 +95,7 @@ class _SplashScreenState extends BaseState { // необходимо запустить регистрацию кассы. if (token == null) { await helper.close(); - pushRoute(context, new RegistrationScreen()); + pushRouteReplacement(context, new RegistrationScreen()); } else { if (await platform.invokeMethod('isOnline')) { checkTokenStatus(token).then((statusResponse) { @@ -115,7 +120,7 @@ class _SplashScreenState extends BaseState { if (code == 404) { helper.clear().then((result) { helper.close().then((_) { - pushRoute(context, new RegistrationScreen()); + pushRouteReplacement(context, new RegistrationScreen()); }); }); } else { @@ -148,7 +153,7 @@ class _SplashScreenState extends BaseState { createToken(merchantID, posID).then((response) { if (response.statusCode == 409) { helper.close(); - pushRoute(context, new FinishRegistrationScreen()); + pushRouteReplacement(context, new FinishRegistrationScreen()); } else if (response.statusCode == 201) { clearToken(response, helper); } @@ -163,7 +168,7 @@ class _SplashScreenState extends BaseState { deleteToken(parsedMap['token']).then((_) { helper.close(); Navigator.of(context).pop(); // Убираем текущий route - pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию + pushRouteReplacement(context, new RegistrationScreen()); // Запускаем регистрацию }).catchError((error) { helper.close(); print(error.toString()); diff --git a/lib/strings.dart b/lib/strings.dart index 0221352..c8fd75f 100644 --- a/lib/strings.dart +++ b/lib/strings.dart @@ -40,8 +40,18 @@ class StringsLocalization { static String buyer() => Intl.message('buyer', name: 'buyer', locale: Intl.defaultLocale); static String idNotFound() => Intl.message('ID_not_found', name: 'ID_not_found', locale: Intl.defaultLocale); static String settings() => Intl.message('settings', name: 'settings', locale: Intl.defaultLocale); - static String help () => Intl.message('help ', name: 'help ', locale: Intl.defaultLocale); + static String help() => Intl.message('help ', name: 'help ', locale: Intl.defaultLocale); static String logout() => Intl.message('logout', name: 'logout', locale: Intl.defaultLocale); static String currency() => Intl.message('currency', name: 'currency', locale: Intl.defaultLocale); static String locale() => Intl.message('locale', name: 'locale', locale: Intl.defaultLocale); + + // Языки + static String russian() => Intl.message('russian', name: 'russian', locale: Intl.defaultLocale); + static String english() => Intl.message('english', name: 'english', locale: Intl.defaultLocale); + static String ukrainian() => Intl.message('ukrainian', name: 'ukrainian', locale: Intl.defaultLocale); + + // Валюты + static String ruble() => Intl.message('rubles', name: 'rubles', locale: Intl.defaultLocale); + static String dollar() => Intl.message('dollars', name: 'dollars', locale: Intl.defaultLocale); + static String hryvna() => Intl.message('hryvna', name: 'hryvna', locale: Intl.defaultLocale); } \ No newline at end of file