Локализация экрана настроек, удалил лишние конфигурации сборки

This commit is contained in:
Ivan Murashov
2017-09-11 11:41:20 +03:00
parent 0dc8ab5da0
commit 0dde204dcd
12 changed files with 131 additions and 57 deletions

View File

@@ -14,15 +14,19 @@ import 'strings.dart';
const platform = const MethodChannel('com.dinect.checker/instance_id'); const platform = const MethodChannel('com.dinect.checker/instance_id');
// Метод обеспечивает замену текущего объекта route новым. // Метод обеспечивает замену текущего объекта route новым.
pushRoute(BuildContext context, Widget widget) { pushRouteReplacement(BuildContext context, Widget widget) {
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => widget); var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => widget);
Navigator.of(context).pushReplacement(route); Navigator.of(context).pushReplacement(route);
} }
pushRoute(BuildContext context, Widget widget) {
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => widget);
Navigator.of(context).push(route);
}
// Добавление route, с возможностью вернуться к предыдущему экрану. // Добавление route, с возможностью вернуться к предыдущему экрану.
faq(BuildContext context, bool returnToScanner) { faq(BuildContext context, bool returnToScanner) {
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => new FAQScreen(returnToScanner)); pushRoute(context, new FAQScreen(returnToScanner));
Navigator.of(context).push(route);
} }
// В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения. // В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения.
@@ -32,14 +36,14 @@ logout(BuildContext context) async {
await helper.open(); await helper.open();
String token = await helper.getToken(); String token = await helper.getToken();
VoidCallback positiveCalback = () { VoidCallback positiveCallback = () {
if (token != null) { if (token != null) {
deleteToken(token).then((response) { deleteToken(token).then((response) {
print(response.body); print(response.body);
platform.invokeMethod('removeKeys').then((result) { platform.invokeMethod('removeKeys').then((result) {
Navigator.of(context).pop(); Navigator.of(context).pop();
Navigator.of(context).pop(); Navigator.of(context).pop();
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию pushRouteReplacement(context, new RegistrationScreen()); // Запускаем регистрацию
}); });
}).catchError((error) { }).catchError((error) {
print(error.toString()); 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 { forceLogout(String token , BuildContext context) async {
@@ -62,7 +66,7 @@ forceLogout(String token , BuildContext context) async {
helper.clear().then((_) { helper.clear().then((_) {
helper.close().then((_) { helper.close().then((_) {
Navigator.of(context).pop(); 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()), child: new Text(StringsLocalization.yes()),
onPressed: positiveCallback)])); 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();
}
}

View File

@@ -90,7 +90,7 @@ class SqliteHelper {
Future<String> getMerchantID() async { Future<String> getMerchantID() async {
Map session = await selectAll(tableSession); Map session = await selectAll(tableSession);
String merchantID = session != null ? session[columnMerchantID] : null; String merchantID = session != null ? session[columnMerchantID] : null;
print('token: {$merchantID}'); print('merchantID: {$merchantID}');
return merchantID; return merchantID;
} }
@@ -107,6 +107,20 @@ class SqliteHelper {
return docID; return docID;
} }
Future<String> getLocale() async {
Map settings = await selectAll(tableSettings);
String locale = settings != null ? settings[columnLocale] : null;
print('locale: {$locale}');
return locale;
}
Future<String> getCurrency() async {
Map settings = await selectAll(tableSettings);
String currency = settings != null ? settings[columnCurrency] : null;
print('currency: {$currency}');
return currency;
}
Future<Map> selectAll(String table) async { Future<Map> selectAll(String table) async {
List<Map> maps = await db.query(table, columns: null); List<Map> maps = await db.query(table, columns: null);

View File

@@ -43,6 +43,13 @@ class MessageLookup extends MessageLookupByLibrary {
"help " : MessageLookupByLibrary.simpleMessage("FAQ"), "help " : MessageLookupByLibrary.simpleMessage("FAQ"),
"logout" : MessageLookupByLibrary.simpleMessage("Logout"), "logout" : MessageLookupByLibrary.simpleMessage("Logout"),
"currency" : MessageLookupByLibrary.simpleMessage("Currency"), "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")
}; };
} }

View File

@@ -38,6 +38,15 @@ class MessageLookup extends MessageLookupByLibrary {
"sum" : MessageLookupByLibrary.simpleMessage("Suma"), "sum" : MessageLookupByLibrary.simpleMessage("Suma"),
"update_activ_status" : MessageLookupByLibrary.simpleMessage("Actualizar la condición de activación"), "update_activ_status" : MessageLookupByLibrary.simpleMessage("Actualizar la condición de activación"),
"user_name" : MessageLookupByLibrary.simpleMessage("Un nombre de usario"), "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")
}; };
} }

View File

@@ -43,6 +43,12 @@ class MessageLookup extends MessageLookupByLibrary {
"help " : MessageLookupByLibrary.simpleMessage("Справка"), "help " : MessageLookupByLibrary.simpleMessage("Справка"),
"logout" : MessageLookupByLibrary.simpleMessage("Выход"), "logout" : MessageLookupByLibrary.simpleMessage("Выход"),
"currency" : 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("Гривна")
}; };
} }

View File

@@ -38,6 +38,15 @@ class MessageLookup extends MessageLookupByLibrary {
"sum" : MessageLookupByLibrary.simpleMessage("Сума"), "sum" : MessageLookupByLibrary.simpleMessage("Сума"),
"update_activ_status" : MessageLookupByLibrary.simpleMessage("Оновити статус активації"), "update_activ_status" : MessageLookupByLibrary.simpleMessage("Оновити статус активації"),
"user_name" : 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")
}; };
} }

View File

@@ -5,20 +5,6 @@ import 'strings.dart';
import 'common.dart'; import 'common.dart';
import 'dart:async'; import 'dart:async';
class StringsLocalizationDelegate extends LocalizationsDelegate<StringsLocalization> {
@override
Future<StringsLocalization> load(Locale locale) async {
return StringsLocalization.load(await platform.invokeMethod("getLocale"));
}
@override
bool shouldReload(LocalizationsDelegate<StringsLocalization> old) {
return false;
}
}
/// Точка входа в приложение. /// Точка входа в приложение.
void main() { void main() {
runApp(new Checker()); runApp(new Checker());
@@ -33,12 +19,7 @@ class CheckerState extends State<Checker> {
@override Widget build(BuildContext context) { @override Widget build(BuildContext context) {
return new MaterialApp( return new MaterialApp(
title: appName, title: appName,
home: new SplashScreen(), home: new SplashScreen());
localizationsDelegates: getLocalizationsDelegate()
);
} }
getLocalizationsDelegate() {
return <StringsLocalizationDelegate>[new StringsLocalizationDelegate()];
}
} }

View File

@@ -220,7 +220,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
print(response.body); print(response.body);
helper.close().then((_) { helper.close().then((_) {
Navigator.of(context).pop(); 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) { }).catchError((error) {

View File

@@ -87,7 +87,7 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
if (response.statusCode == 201) { if (response.statusCode == 201) {
helper.createSession(dinCode, posID, parsedMap['token']).then((_) { helper.createSession(dinCode, posID, parsedMap['token']).then((_) {
helper.close(); helper.close();
pushRoute(context, new FinishRegistrationScreen()); pushRouteReplacement(context, new FinishRegistrationScreen());
}); });
} else { } else {
setState(() { setState(() {

View File

@@ -17,10 +17,10 @@ class SettingsScreen extends StatefulWidget {
class MenuItem { class MenuItem {
MenuItem(); // Заголовок пункта меню и выбранное значение.
String title, selectedValue;
String title; MenuItem(this.title, this.selectedValue);
String selectedValue;
} }
class _SettingsState extends BaseState<SettingsScreen> { class _SettingsState extends BaseState<SettingsScreen> {
@@ -31,16 +31,11 @@ class _SettingsState extends BaseState<SettingsScreen> {
if (menuItems == null) { if (menuItems == null) {
helper.getSettings().then((info) { helper.getSettings().then((info) {
setState(() { setState(() {
print("load settings"); print("load settings");
menuItems = [
menuItems = [new MenuItem(), new MenuItem()]; new MenuItem(StringsLocalization.locale(), getLocaleTitle(info["locale"])),
new MenuItem(StringsLocalization.currency(), getCurrencyTitle(info["currency"]))
menuItems[0].title = StringsLocalization.locale(); ];
menuItems[0].selectedValue = info["locale"];
menuItems[1].title = StringsLocalization.currency();
menuItems[1].selectedValue = info["currency"].toString();
}); });
}); });
} }
@@ -53,17 +48,35 @@ class _SettingsState extends BaseState<SettingsScreen> {
: new ListView(children: getSettings()); : new ListView(children: getSettings());
} }
@override
List<Widget> getMenuButtons() {
return null;
}
List<Widget> getSettings() { List<Widget> getSettings() {
List<Widget> widgets = new List(); List<Widget> widgets = new List();
for (MenuItem item in menuItems) { for (MenuItem item in menuItems) {
widgets.add(new Row(children: [ widgets.add(getSettingsItem(item));
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)]));
} }
return widgets; return widgets;
} }
Widget getSettingsItem(MenuItem item) {
return new Container(
margin: const EdgeInsets.all(16.0),
child: new Row(children: <Widget>[
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 @override
String getTitle() { String getTitle() {
return StringsLocalization.settings(); return StringsLocalization.settings();

View File

@@ -1,3 +1,4 @@
import 'package:checker/strings.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
@@ -26,7 +27,6 @@ class _SplashScreenState extends BaseState<SplashScreen> {
helper.getSettings().then((info) { helper.getSettings().then((info) {
if (info == null) { if (info == null) {
platform.invokeMethod('getLocale').then((locale) { platform.invokeMethod('getLocale').then((locale) {
Intl.defaultLocale = locale;
platform.invokeMethod('getCurrency').then((currency) { platform.invokeMethod('getCurrency').then((currency) {
helper.createAppInfo(locale, currency).then((_) { helper.createAppInfo(locale, currency).then((_) {
showNext(); showNext();
@@ -34,7 +34,12 @@ class _SplashScreenState extends BaseState<SplashScreen> {
}); });
}); });
} else { } else {
showNext(); helper.getLocale().then((locale) {
Intl.defaultLocale = locale;
StringsLocalization.load(locale).then((l) {
showNext();
});
});
} }
}); });
} }
@@ -90,7 +95,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
// необходимо запустить регистрацию кассы. // необходимо запустить регистрацию кассы.
if (token == null) { if (token == null) {
await helper.close(); await helper.close();
pushRoute(context, new RegistrationScreen()); pushRouteReplacement(context, new RegistrationScreen());
} else { } else {
if (await platform.invokeMethod('isOnline')) { if (await platform.invokeMethod('isOnline')) {
checkTokenStatus(token).then((statusResponse) { checkTokenStatus(token).then((statusResponse) {
@@ -115,7 +120,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
if (code == 404) { if (code == 404) {
helper.clear().then((result) { helper.clear().then((result) {
helper.close().then((_) { helper.close().then((_) {
pushRoute(context, new RegistrationScreen()); pushRouteReplacement(context, new RegistrationScreen());
}); });
}); });
} else { } else {
@@ -148,7 +153,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
createToken(merchantID, posID).then((response) { createToken(merchantID, posID).then((response) {
if (response.statusCode == 409) { if (response.statusCode == 409) {
helper.close(); helper.close();
pushRoute(context, new FinishRegistrationScreen()); pushRouteReplacement(context, new FinishRegistrationScreen());
} else if (response.statusCode == 201) { } else if (response.statusCode == 201) {
clearToken(response, helper); clearToken(response, helper);
} }
@@ -163,7 +168,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
deleteToken(parsedMap['token']).then((_) { deleteToken(parsedMap['token']).then((_) {
helper.close(); helper.close();
Navigator.of(context).pop(); // Убираем текущий route Navigator.of(context).pop(); // Убираем текущий route
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию pushRouteReplacement(context, new RegistrationScreen()); // Запускаем регистрацию
}).catchError((error) { }).catchError((error) {
helper.close(); helper.close();
print(error.toString()); print(error.toString());

View File

@@ -40,8 +40,18 @@ class StringsLocalization {
static String buyer() => Intl.message('buyer', name: 'buyer', locale: Intl.defaultLocale); 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 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 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 logout() => Intl.message('logout', name: 'logout', locale: Intl.defaultLocale);
static String currency() => Intl.message('currency', name: 'currency', 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 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);
} }