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

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');
// Метод обеспечивает замену текущего объекта route новым.
pushRoute(BuildContext context, Widget widget) {
pushRouteReplacement(BuildContext context, Widget widget) {
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => widget);
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, с возможностью вернуться к предыдущему экрану.
faq(BuildContext context, bool returnToScanner) {
var route = new MaterialPageRoute<Null>(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();
}
}

View File

@@ -90,7 +90,7 @@ class SqliteHelper {
Future<String> 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<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 {
List<Map> maps = await db.query(table, columns: null);

View File

@@ -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")
};
}

View File

@@ -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")
};
}

View File

@@ -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("Гривна")
};
}

View File

@@ -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")
};
}

View File

@@ -5,20 +5,6 @@ import 'strings.dart';
import 'common.dart';
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() {
runApp(new Checker());
@@ -33,12 +19,7 @@ class CheckerState extends State<Checker> {
@override Widget build(BuildContext context) {
return new MaterialApp(
title: appName,
home: new SplashScreen(),
localizationsDelegates: getLocalizationsDelegate()
);
home: new SplashScreen());
}
getLocalizationsDelegate() {
return <StringsLocalizationDelegate>[new StringsLocalizationDelegate()];
}
}

View File

@@ -220,7 +220,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
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) {

View File

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

View File

@@ -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<SettingsScreen> {
@@ -31,16 +31,11 @@ class _SettingsState extends BaseState<SettingsScreen> {
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<SettingsScreen> {
: new ListView(children: getSettings());
}
@override
List<Widget> getMenuButtons() {
return null;
}
List<Widget> getSettings() {
List<Widget> 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: <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
String getTitle() {
return StringsLocalization.settings();

View File

@@ -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<SplashScreen> {
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<SplashScreen> {
});
});
} else {
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) {
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<SplashScreen> {
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<SplashScreen> {
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<SplashScreen> {
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());

View File

@@ -44,4 +44,14 @@ class StringsLocalization {
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);
}