Упрощена работа с локалью, базовый url и токен приложения вынесены в build.gradle, добавлен конфиг для разработки и тестирования, исправлена проблема с переходом на экран сканера если локаль не выбиралась в настройках

This commit is contained in:
kifio
2017-09-23 23:19:32 +03:00
parent 808d5a39e5
commit 40fed84275
15 changed files with 277 additions and 255 deletions

View File

@@ -11,58 +11,64 @@ import 'package:checker/strings.dart';
import 'package:flutter/material.dart';
// Пакет для обработки json с ответом от сервера.
/// Экран регистрации магазина и кассы.
class RegistrationScreen extends BaseScreen {
RegistrationScreen(helper, app) : super(helper, app);
@override State createState() => new RegistrationScreenState(helper, app);
@override
State createState() => new RegistrationScreenState(helper, app);
}
class RegistrationScreenState extends BaseState<RegistrationScreen> {
RegistrationScreenState(SqliteHelper helper, String app) {
this.helper = helper;
this.app = app;
}
@override Widget build(BuildContext ctx) {
@override
Widget build(BuildContext ctx) {
return getMainWidget();
}
@override String getTitle() {
@override
String getTitle() {
return StringsLocalization.registration();
}
@override getHintString() {
@override
getHintString() {
return StringsLocalization.idStore();
}
/// Список виджетов, автоматически прокручиваемый вверх при открытии клавиатуры.
@override Widget getScreenContent() {
@override
Widget getScreenContent() {
return new Container(
child: new ListView(children: <Widget>[
new Column(children: <Widget>[
getLogo(),
getHintLabel(),
getInputField(),
getButton()
])
]));
new Column(children: <Widget>[
getLogo(),
getHintLabel(),
getInputField(),
getButton()
])
]));
}
@override getTextWidget() {
return new TextField(keyboardType: TextInputType.number,
decoration: new InputDecoration.collapsed(hintText: getHintString(),
@override
getTextWidget() {
return new TextField(
keyboardType: TextInputType.number,
decoration: new InputDecoration.collapsed(
hintText: getHintString(),
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
onChanged: (text) => handleUserInput(text));
}
/// Возвращает кнопку регистрации.
getButton() {
return new Container(margin: new EdgeInsets.only(top: 36.0), child:
buildRaisedButton(StringsLocalization.signUp(), getOnPressed()));
return new Container(
margin: new EdgeInsets.only(top: 36.0),
child: buildRaisedButton(StringsLocalization.signUp(), getOnPressed()));
}
// Возвращает обработчик нажатий на кнопку регистрации.
@@ -70,10 +76,10 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
return _isValidMerchantID() && !loading ? () => _registerShop() : null;
}
/// Токен кассы - это DIN код. DIN код - это специальный код динекта, максимальная его длина - 25 символов.
/// Токен кассы - это DIN код. DIN код - это специальный код динекта, максимальная его длина - 25 символов.
_isValidMerchantID() {
print("${dinCode.length}");
return dinCode.length > 0 && dinCode.length < 25;
print("${merchantID.length}");
return merchantID.length > 0 && merchantID.length < 25;
}
/// Показать progressBar, запросить токен.
@@ -88,8 +94,9 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
_register() async {
if (await platform.invokeMethod('isOnline')) {
String posID = await helper.getPosID();
String locale = await helper.getLocale();
createToken(dinCode, posID, locale).then((response) {
getCreateTokenRequest({'merchant_shop': merchantID, 'pos': posID})
.then((response) {
setState(() {
error = null;
loading = false;
@@ -100,8 +107,9 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
Map parsedMap = JSON.decode(response.body);
if (response.statusCode == 201) {
helper.createSession(dinCode, posID, parsedMap['token']).then((_) {
pushRouteReplacement(context, new FinishRegistrationScreen(helper, app));
helper.createSession(merchantID, posID, parsedMap['token']).then((_) {
pushRouteReplacement(
context, new FinishRegistrationScreen(helper, app));
});
} else {
setState(() {
@@ -113,4 +121,4 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
});
}
}
}
}