Упрощена работа с локалью, базовый url и токен приложения вынесены в build.gradle, добавлен конфиг для разработки и тестирования, исправлена проблема с переходом на экран сканера если локаль не выбиралась в настройках
This commit is contained in:
@@ -9,6 +9,7 @@ import 'package:checker/network.dart';
|
||||
import 'package:checker/strings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class FinishRegistrationScreen extends BaseScreen {
|
||||
|
||||
@@ -66,8 +67,7 @@ class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
|
||||
} else {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
String token = await helper.getToken();
|
||||
String locale = await helper.getLocale();
|
||||
checkTokenStatus(token, locale).then((response) {
|
||||
getCheckTokenStatusRequest(token).then((response) {
|
||||
Map parsedMap = JSON.decode(response.body);
|
||||
|
||||
// Обновить экран, заменить сообщение о необходимости активации токена, на сообщние о том, что токен активен.
|
||||
|
||||
@@ -45,18 +45,8 @@ class LanguagesState extends SettingsBaseState<LanguagesScreen> {
|
||||
|
||||
@override
|
||||
void getSelectedValue() {
|
||||
helper.getLocale().then((locale) {
|
||||
if (locale == null) {
|
||||
platform.invokeMethod('getLocale').then((locale) {
|
||||
setState(() {
|
||||
selectedItem == locale;
|
||||
});
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
selectedItem = getOptions().indexOf(getLocaleTitle(locale));
|
||||
});
|
||||
}
|
||||
setState(() {
|
||||
selectedItem = getOptions().indexOf(getLocaleTitle(Intl.defaultLocale));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -14,17 +14,16 @@ import 'package:checker/screens/purchase_success.dart';
|
||||
|
||||
/// Экран проведения покупки.
|
||||
class PurchaseScreen extends StatefulWidget {
|
||||
|
||||
PurchaseScreen(this.user, this.card);
|
||||
|
||||
final String user;
|
||||
final String card;
|
||||
|
||||
@override State createState() => new PurchaseScreenState<PurchaseScreen>(user, card);
|
||||
@override
|
||||
State createState() => new PurchaseScreenState<PurchaseScreen>(user, card);
|
||||
}
|
||||
|
||||
class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
|
||||
/// Объект, помогающий вручную изменять введенный пользователем текст.
|
||||
/// Используется для форматирования введенных пользователем данных
|
||||
/// (удаляет запрещенные символы до их отображаения).
|
||||
@@ -35,7 +34,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
this.card = card;
|
||||
}
|
||||
|
||||
@override Widget build(BuildContext ctx) {
|
||||
@override
|
||||
Widget build(BuildContext ctx) {
|
||||
if (helper == null) {
|
||||
helper = new SqliteHelper();
|
||||
helper.open().then((_) {
|
||||
@@ -43,7 +43,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
platform.invokeMethod('getFlavor').then((flavor) {
|
||||
app = flavor;
|
||||
setState(() {
|
||||
getLoyalty(user['loyalty_url']);
|
||||
requestLoyalty(user['loyalty_url']);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -57,17 +57,24 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
String card = '';
|
||||
String loyalty = '';
|
||||
|
||||
@override Widget getScreenContent() {
|
||||
return new Column(
|
||||
children: <Widget>[new Expanded(child: new ListView(children: <Widget>[
|
||||
getValueWithDescription(StringsLocalization.buyer(), user['first_name'] == null ? '' : user['first_name']),
|
||||
getValueWithDescription(StringsLocalization.card(), card),
|
||||
getValueWithDescription(StringsLocalization.reward(), loyalty),
|
||||
getHintLabel(),
|
||||
getInputField(),
|
||||
wrapButton(getScreenMargins(36.0), getCompleteButton()),
|
||||
wrapButton(getScreenMargins(24.0), getScanButton(context, StringsLocalization.scan(), Resources.getPrimaryColor(app)))
|
||||
]))]);
|
||||
@override
|
||||
Widget getScreenContent() {
|
||||
return new Column(children: <Widget>[
|
||||
new Expanded(
|
||||
child: new ListView(children: <Widget>[
|
||||
getValueWithDescription(StringsLocalization.buyer(),
|
||||
user['first_name'] == null ? '' : user['first_name']),
|
||||
getValueWithDescription(StringsLocalization.card(), card),
|
||||
getValueWithDescription(StringsLocalization.reward(), loyalty),
|
||||
getHintLabel(),
|
||||
getInputField(),
|
||||
wrapButton(getScreenMargins(36.0), getCompleteButton()),
|
||||
wrapButton(
|
||||
getScreenMargins(24.0),
|
||||
getScanButton(context, StringsLocalization.scan(),
|
||||
Resources.getPrimaryColor(app)))
|
||||
]))
|
||||
]);
|
||||
}
|
||||
|
||||
getScreenMargins(double top) {
|
||||
@@ -76,37 +83,39 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
}
|
||||
|
||||
getCompleteButton() {
|
||||
return buildRaisedButton(StringsLocalization.completePurchase(), () => onPurchaseClick());
|
||||
return buildRaisedButton(
|
||||
StringsLocalization.completePurchase(), () => onPurchaseClick());
|
||||
}
|
||||
|
||||
Widget getScanButton(BuildContext context, String title, Color textColor) {
|
||||
return new Container(
|
||||
height: buttonHeight,
|
||||
child: new FlatButton(
|
||||
child: new Text(
|
||||
title,
|
||||
style: new TextStyle(color: textColor)),
|
||||
child: new Text(title, style: new TextStyle(color: textColor)),
|
||||
onPressed: () => startScanner(context, app, helper)),
|
||||
decoration: new BoxDecoration(
|
||||
border: new Border.all(color: Resources.getButtonColor(app), width: 1.0),
|
||||
border: new Border.all(
|
||||
color: Resources.getButtonColor(app), width: 1.0),
|
||||
borderRadius: new BorderRadius.all(new Radius.circular(4.0))));
|
||||
}
|
||||
|
||||
@override String getTitle() {
|
||||
@override
|
||||
String getTitle() {
|
||||
return StringsLocalization.carryingPurchase();
|
||||
}
|
||||
|
||||
@override getHintString() {
|
||||
@override
|
||||
getHintString() {
|
||||
return StringsLocalization.sum();
|
||||
}
|
||||
|
||||
@override getTextWidget() {
|
||||
@override
|
||||
getTextWidget() {
|
||||
return new TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: new InputDecoration.collapsed(
|
||||
hintText: getHintString(),
|
||||
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)
|
||||
),
|
||||
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
|
||||
controller: controller,
|
||||
onSubmitted: (String text) {
|
||||
setState(() {
|
||||
@@ -118,33 +127,11 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
getLoyalty(String url) async {
|
||||
|
||||
requestLoyalty(String url) async {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
|
||||
String token = await helper.getToken();
|
||||
String locale = await helper.getLocale();
|
||||
|
||||
var headers = {
|
||||
'DM-Authorization': 'dmapptoken $appToken',
|
||||
'Authorization': 'dmtoken ${token}',
|
||||
'Accept-Language': locale
|
||||
};
|
||||
|
||||
httpClient.get(url, headers: headers).then((response) {
|
||||
|
||||
print(response.body);
|
||||
|
||||
Map bonuses = JSON.decode(response.body);
|
||||
String type = bonuses['type'];
|
||||
getLoyaltyRequest(url, helper).then((response) {
|
||||
setState(() {
|
||||
if (type == 'amount') {
|
||||
this.loyalty = '${user['discount']}%';
|
||||
} else {
|
||||
List amountToBonus = bonuses['amount_to_bonus'];
|
||||
double loyaltyVal = (double.parse(amountToBonus[1]) / amountToBonus[0]) * 100;
|
||||
this.loyalty = '${loyaltyVal.toStringAsFixed(0)}%';
|
||||
}
|
||||
setBonuses(JSON.decode(response.body));
|
||||
});
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
@@ -152,15 +139,15 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Переделать? чтобы работало хорошо
|
||||
String _cleanupNumber(String text){
|
||||
// TODO: Переделать, если потребуется
|
||||
String _cleanupNumber(String text) {
|
||||
String tmp = text
|
||||
.replaceAll(' ', '')
|
||||
.replaceAll('-', '')
|
||||
.replaceAll(',', '.')
|
||||
.replaceAll('..', '.');
|
||||
|
||||
while(tmp.indexOf('..') != -1){
|
||||
while (tmp.indexOf('..') != -1) {
|
||||
tmp = tmp.replaceAll('..', '.');
|
||||
}
|
||||
return tmp;
|
||||
@@ -172,17 +159,17 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
|
||||
try {
|
||||
sumTotal = num.parse(text);
|
||||
} catch(exception) {
|
||||
} catch (exception) {
|
||||
print(exception);
|
||||
try {
|
||||
int idx = text.indexOf('.');
|
||||
String integerPart = text.substring(0, idx);
|
||||
String fractionalPart = text.substring(idx + 1, text.length);
|
||||
if(fractionalPart.length > 2) {
|
||||
if (fractionalPart.length > 2) {
|
||||
fractionalPart = fractionalPart.substring(0, 2);
|
||||
}
|
||||
return '${integerPart}.${fractionalPart}';
|
||||
} catch(exception){
|
||||
} catch (exception) {
|
||||
print(exception);
|
||||
}
|
||||
}
|
||||
@@ -193,23 +180,26 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
String val = _parseSum(controller.text);
|
||||
helper.getCurrency().then((currency) {
|
||||
print(currency.toString());
|
||||
showDialog(context: context, child: new AlertDialog(
|
||||
title: new Text(StringsLocalization.confirmation()),
|
||||
content: new Text(StringsLocalization.confirmPurchase(val, currency)),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text(StringsLocalization.no()),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
new FlatButton(
|
||||
child: new Text(StringsLocalization.yes()),
|
||||
onPressed: () {
|
||||
purchase(val);
|
||||
},
|
||||
)
|
||||
]));
|
||||
showDialog(
|
||||
context: context,
|
||||
child: new AlertDialog(
|
||||
title: new Text(StringsLocalization.confirmation()),
|
||||
content:
|
||||
new Text(StringsLocalization.confirmPurchase(val, currency)),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text(StringsLocalization.no()),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
new FlatButton(
|
||||
child: new Text(StringsLocalization.yes()),
|
||||
onPressed: () {
|
||||
purchase(val);
|
||||
},
|
||||
)
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -219,11 +209,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
purchaseInProgress = true;
|
||||
|
||||
String token = await helper.getToken();
|
||||
String locale = await helper.getLocale();
|
||||
helper.getMerchantID().then((result) {
|
||||
|
||||
String url = user['purchases_url'];
|
||||
|
||||
helper.getCurrency().then((currency) {
|
||||
var body = {
|
||||
'doc_id': result,
|
||||
@@ -232,14 +218,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
'sum_total': sumTotal
|
||||
};
|
||||
|
||||
var headers = {
|
||||
'DM-Authorization': 'dmapptoken $appToken',
|
||||
'Authorization': 'dmtoken ${token}',
|
||||
'Accept-Language': locale
|
||||
};
|
||||
|
||||
httpClient.post(url, body: body, headers: headers).then((response) {
|
||||
|
||||
getPurchaseRequest(user['purchases_url'], body, token)
|
||||
.then((response) {
|
||||
print(response.body);
|
||||
Map parsedMap = JSON.decode(response.body);
|
||||
|
||||
@@ -247,11 +227,18 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
|
||||
if (parsedMap.containsKey('errors')) {
|
||||
List<String> errors = parsedMap['errors'];
|
||||
Scaffold.of(context).showSnackBar(new SnackBar(content: new Text(errors[0])));
|
||||
Scaffold
|
||||
.of(context)
|
||||
.showSnackBar(new SnackBar(content: new Text(errors[0])));
|
||||
} else {
|
||||
pushRouteReplacement(context, new PurchaseSuccessScreen(sumTotal, user['first_name'] == null ? '' : user['first_name'], helper, app));
|
||||
pushRouteReplacement(
|
||||
context,
|
||||
new PurchaseSuccessScreen(
|
||||
sumTotal,
|
||||
user['first_name'] == null ? '' : user['first_name'],
|
||||
helper,
|
||||
app));
|
||||
}
|
||||
|
||||
}).catchError((error) {
|
||||
purchaseInProgress = false;
|
||||
print(error.toString());
|
||||
@@ -261,4 +248,14 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setBonuses(Map bonuses) {
|
||||
if (bonuses['type'] == 'amount') {
|
||||
this.loyalty = '${user['discount']}%';
|
||||
} else {
|
||||
double loyaltyVal = (double.parse(bonuses['amount_to_bonus'][1]) /
|
||||
bonuses['amount_to_bonus'][0]) * 100;
|
||||
this.loyalty = '${loyaltyVal.toStringAsFixed(0)}%';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,13 @@ import 'package:http/http.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class SplashScreen extends StatefulWidget {
|
||||
@override State createState() => new _SplashScreenState();
|
||||
@override
|
||||
State createState() => new _SplashScreenState();
|
||||
}
|
||||
|
||||
class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
|
||||
@override Widget build(BuildContext ctx) {
|
||||
@override
|
||||
Widget build(BuildContext ctx) {
|
||||
if (helper == null) {
|
||||
helper = new SqliteHelper();
|
||||
helper.open().then((_) {
|
||||
@@ -42,7 +43,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
if (locale == null) {
|
||||
initWithSystemValue();
|
||||
} else {
|
||||
initWithSavedValue();
|
||||
initWithSavedValue(locale);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -61,17 +62,15 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
void initWithSavedValue() {
|
||||
helper.getLocale().then((locale) {
|
||||
initLocale(locale, () {
|
||||
showNext();
|
||||
});
|
||||
void initWithSavedValue(String locale) {
|
||||
initLocale(locale, () {
|
||||
showNext();
|
||||
});
|
||||
}
|
||||
|
||||
void createSettingsTable(String locale) {
|
||||
platform.invokeMethod('getCurrency').then((currency) {
|
||||
helper.createAppInfo(locale, currency);
|
||||
helper.createAppInfo(currency);
|
||||
initLocale(locale, () {
|
||||
showNext();
|
||||
});
|
||||
@@ -95,44 +94,31 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
Widget getScreenContent() {
|
||||
return app == null
|
||||
? getBackground()
|
||||
: new Stack(
|
||||
children: <Widget>[
|
||||
getBackground(),
|
||||
getLogo(),
|
||||
new Align(
|
||||
alignment: FractionalOffset.bottomRight,
|
||||
child: new Container(
|
||||
margin: new EdgeInsets.only(
|
||||
right: 11.0,
|
||||
bottom: 5.0),
|
||||
child: new Image.asset(powered_by_dinect_splash_png,
|
||||
height: 16.0,
|
||||
width: 122.0)))
|
||||
]);
|
||||
: new Stack(children: <Widget>[
|
||||
getBackground(),
|
||||
getLogo(),
|
||||
new Align(
|
||||
alignment: FractionalOffset.bottomRight,
|
||||
child: new Container(
|
||||
margin: new EdgeInsets.only(right: 11.0, bottom: 5.0),
|
||||
child: new Image.asset(powered_by_dinect_splash_png,
|
||||
height: 16.0, width: 122.0)))
|
||||
]);
|
||||
}
|
||||
|
||||
/// Возвращает столбец с логотипом приложения и текстом под ним.
|
||||
/// Столбец занимает не все доступное пространство, а необходимый минимум в центре экрана.
|
||||
getLogo() {
|
||||
return new Center(
|
||||
child: new Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
new Image.asset(
|
||||
Resources.getLogo(app),
|
||||
height: 112.0,
|
||||
width: 252.0),
|
||||
new Image.asset(
|
||||
splash_text_png,
|
||||
height: 40.0,
|
||||
width: 240.0)
|
||||
]));
|
||||
child: new Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
||||
new Image.asset(Resources.getLogo(app), height: 112.0, width: 252.0),
|
||||
new Image.asset(splash_text_png, height: 40.0, width: 240.0)
|
||||
]));
|
||||
}
|
||||
|
||||
/// Запуск следующего экрана приложения.
|
||||
showNextScreen() async {
|
||||
String token = await helper.getToken();
|
||||
String locale = await helper.getLocale();
|
||||
|
||||
// В случае, если в приложении отсутствует токен,
|
||||
// необходимо запустить регистрацию кассы.
|
||||
@@ -140,7 +126,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
pushRouteReplacement(context, new RegistrationScreen(helper, app));
|
||||
} else {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
checkTokenStatus(token, locale).then((statusResponse) {
|
||||
getCheckTokenStatusRequest(token).then((statusResponse) {
|
||||
handleStatusResponse(statusResponse, helper);
|
||||
}).catchError((error) {
|
||||
handleError(error.toString());
|
||||
@@ -183,11 +169,12 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
_createToken(SqliteHelper helper) async {
|
||||
String merchantID = await helper.getMerchantID();
|
||||
String posID = await helper.getPosID();
|
||||
String locale = await helper.getLocale();
|
||||
|
||||
createToken(merchantID, posID, locale).then((response) {
|
||||
getCreateTokenRequest({'merchant_shop': merchantID, 'pos': posID})
|
||||
.then((response) {
|
||||
if (response.statusCode == 409) {
|
||||
pushRouteReplacement(context, new FinishRegistrationScreen(helper, app));
|
||||
pushRouteReplacement(
|
||||
context, new FinishRegistrationScreen(helper, app));
|
||||
} else if (response.statusCode == 201) {
|
||||
clearToken(response, helper);
|
||||
}
|
||||
@@ -198,10 +185,9 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
|
||||
/// Очищаем бд, делаем запрос на удаление токена.
|
||||
Future clearToken(Response response, SqliteHelper helper) async {
|
||||
String locale = await helper.getLocale();
|
||||
helper.clear().then((_) {
|
||||
Map parsedMap = JSON.decode(response.body);
|
||||
deleteToken(parsedMap['token'], locale).then((_) {
|
||||
getDeleteTokenRequest(parsedMap['token']).then((_) {
|
||||
Navigator.of(context).pop();
|
||||
pushRouteReplacement(context, new RegistrationScreen(helper, app));
|
||||
}).catchError((error) {
|
||||
|
||||
Reference in New Issue
Block a user