Hide discount widgets for crypto flavor

This commit is contained in:
Ivan Murashov
2018-03-09 20:08:28 +03:00
parent 86e3f4ba4c
commit bd1e0ec17f
12 changed files with 95 additions and 73 deletions

View File

@@ -253,7 +253,7 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
EdgeInsets getInputFieldContainerPadding() {
const double verticalPadding = 12.0;
const double horizontalPadding = 16.0;
return new EdgeInsets.only(top: 256.0,
return new EdgeInsets.only(top: verticalPadding,
bottom: verticalPadding,
left: horizontalPadding,
right: horizontalPadding);
@@ -352,7 +352,7 @@ class EnsureVisibleWhenFocusedState extends State<EnsureVisibleWhenFocused> {
// TODO: position doesn't seem to notify listeners when metrics change,
// perhaps a NotificationListener around the scrollable could avoid
// the need insert a delay here.
await new Future.delayed(const Duration(milliseconds: 300));
await new Future.delayed(const Duration(milliseconds: 1000));
if (!widget.focusNode.hasFocus)
return;

View File

@@ -43,8 +43,9 @@ initWithSystemValue(String app, String name, SqliteHelper helper) {
createSettingsTable(String app, String name, String locale, SqliteHelper helper) {
platform.invokeMethod('getCurrency').then((currency) {
helper.createAppInfo(currency);
start(app, name, locale, helper);
helper.createAppInfo(currency).then(() {
start(app, name, locale, helper);
});
});
}

View File

@@ -28,7 +28,7 @@ class Resources {
case 'autobonus': return new Color(0xffeb0004);
case 'dinect': return new Color(0xff33cc99);
case 'dinect': return new Color(0xff33cc99);
case 'crypto': return new Color(0x0f3d87);
case 'crypto': return new Color(0xff0f3d87);
default: return new Color(0xffffffff);
}
}

View File

@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:async';
import 'package:checker/base/base_screen.dart';
import 'package:checker/base/base_state.dart';
@@ -57,9 +58,11 @@ class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
// Если токен активирован, то открывается экран со сканером,
// Если нет, то отправляется запрос на проверку статуса токена.
handleTap() async {
print('tokenActive: $_tokenActive');
if (_tokenActive) {
Navigator.of(context).pop();
// FIXME: startScanner(context, app, helper);
new Future.delayed(const Duration(milliseconds: 200), () {
Navigator.of(context).pop();
});
} else {
if (await platform.invokeMethod('isOnline')) {
String token = await helper.getToken();

View File

@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:convert';
import 'dart:core';
import 'dart:async';
import 'package:checker/resources.dart';
import 'package:checker/strings.dart';
@@ -33,6 +34,9 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
TextEditingController bonusController = new TextEditingController();
FocusNode _focusNodeSum = new FocusNode();
FocusNode _focusNodeBonus = new FocusNode();
PurchaseScreenState(SqliteHelper helper, String app, String userString, String card) : super(helper, app) {
this.user = JSON.decode(userString);
this.card = card;
@@ -56,7 +60,6 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
bool purchaseInProgress = false;
Map user;
String card = '';
String flavor = '';
String loyalityType = '';
String loyalty = '';
String bonus = '';
@@ -72,17 +75,19 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
));
widgetList.add(getValueWithDescription(StringsLocalization.card(), card));
widgetList.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
if (app != 'crypto') { // FIXME Заменить на crypto
widgetList.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
}
if (bonus.length > 0) {
widgetList.add(getValueWithDescription(StringsLocalization.bonus(), bonus));
}
widgetList.add(getHintLabel());
widgetList.add(getInputField()); // Нельзя добавить еще одно поле таким же способом
if (this.flavor != 'autobonus') {
if (app != 'autobonus') {
if (this.loyalityType == 'bonus') {
widgetList.add(getBonusInputField());
}
@@ -114,6 +119,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
Resources.getPrimaryColor(app)
)
));
return new Column(children: <Widget>[
new Expanded(
child: new ListView(children: widgetList))
@@ -121,7 +127,11 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
}
getBonusInputField() {
TextField bonusTextField = new TextField(
var bonusTextField = new EnsureVisibleWhenFocused(
focusNode: _focusNodeBonus,
child: new TextField(
focusNode: _focusNodeBonus,
keyboardType: TextInputType.number,
decoration: new InputDecoration.collapsed(
hintText: StringsLocalization.bonusHint(),
@@ -134,7 +144,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
});
},
textAlign: TextAlign.center,
);
));
return new Column(
children: <Widget>[
@@ -199,7 +209,10 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
@override
getTextWidget() {
// ?? TODO переделать, т.к. позволяет иметь только одно поле ввода на странице
return new TextField(
return new EnsureVisibleWhenFocused(
focusNode: _focusNodeSum,
child: new TextField(
focusNode: _focusNodeSum,
keyboardType: TextInputType.number,
decoration: new InputDecoration.collapsed(
hintText: getHintString(),
@@ -212,12 +225,11 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
},
textAlign: TextAlign.center,
autofocus: true
);
));
}
requestAsyncData(Map user) async {
bool showBonus = await platform.invokeMethod('showBonus');
String flavor = await platform.invokeMethod('getFlavor');
if (await platform.invokeMethod('isOnline') && !this.dataRequested) {
this.dataRequested = true;
var response, couponResponse;
@@ -240,12 +252,10 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
});
setState(() {
this.flavor = flavor;
this.coupons = coupons['results'];
this.loyalityType = loyality['type'];
setBonuses(loyality, showBonus);
});
}
}
@@ -321,7 +331,6 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
showDialog(
context: context,
child: new AlertDialog(
//title: new Text(StringsLocalization.()),
content: new Text(errorText),
actions: <Widget>[
new FlatButton(
@@ -395,17 +404,20 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
Map coupons = JSON.decode(couponsResponse.body);
pushRouteReplacement(
context,
new PurchaseSuccessScreen(
new Future.delayed(const Duration(milliseconds: 200), () {
print('show purchase success!');
var route = new MaterialPageRoute<bool>(builder: (BuildContext context) => new PurchaseSuccessScreen(
sumTotal,
user['first_name'] == null ? '' : user['first_name'],
helper,
app,
purchase,
coupons['results']
)
);
), fullscreenDialog: true);
Navigator.of(context).push(route).then((b) {
print('finish registration closed: $b');
});
});
}
}
}
@@ -427,8 +439,4 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
print('kifio ' + this.loyalty);
print('bonus ' + this.bonus);
}
// onWillPop() {
// return startScanner(context, app, helper);
// }
}

View File

@@ -40,7 +40,6 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
int bonusMinus = 0;
int currency;
bool showBonus;
String flavor;
@override String getTitle() {
return StringsLocalization.carryingPurchase();
@@ -51,6 +50,7 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
}
@override Widget build(BuildContext context) {
if (currency == null) {
helper.getCurrency().then((currency) {
setState(() {
@@ -58,27 +58,20 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
});
});
}
if (this.flavor == null) {
platform.invokeMethod('getFlavor').then((flavor) {
setState(() {
this.flavor = flavor;
if (this.details['sum_bonus'] is String) {
String regexString = r'(\d+) начислено, (\d+).*';
RegExp regExp = new RegExp(regexString);
var matches = regExp.allMatches(this.details['sum_bonus']);
if(matches.length != 0) {
var match = matches.elementAt(0); // => extract the first (and only) match
this.bonusPlus = int.parse(match.group(1));
this.bonusMinus = int.parse(match.group(2));
}
}
if (this.details['sum_bonus'] is String) {
String regexString = r'(\d+) начислено, (\d+).*';
RegExp regExp = new RegExp(regexString);
var matches = regExp.allMatches(this.details['sum_bonus']);
if(matches.length != 0) {
var match = matches.elementAt(0); // => extract the first (and only) match
this.bonusPlus = int.parse(match.group(1));
this.bonusMinus = int.parse(match.group(2));
}
}
if (this.details['sum_bonus'] is int) {
this.bonusPlus = this.details['sum_bonus'];
}
});
});
if (this.details['sum_bonus'] is int) {
this.bonusPlus = this.details['sum_bonus'];
}
return getMainWidget();
@@ -97,13 +90,13 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
widgetList.add(getValueWithDescription(StringsLocalization.bonusMinus(), bonusMinus.toString()));
}
if (this.flavor != 'autobonus') {
if (app != 'autobonus') {
widgetList.add(getValueWithDescription(StringsLocalization.discountRate(), '${details['discount']}%'));
widgetList.add(getValueWithDescription(StringsLocalization.discountSum(), '${details['sum_discount']}'));
if (app != 'crypto') {
widgetList.add(getValueWithDescription(StringsLocalization.discountSum(), '${details['sum_discount']}'));
}
}
// widgetList.add( new Expanded(child: new Center()));
if (this.coupons.length > 0) {
if (app != 'crypto' && this.coupons.length > 0) {
widgetList.add(getItemTitle(StringsLocalization.couponsUsed()));
this.coupons.forEach((couponItem) {
widgetList.add(getItemToggle(
@@ -140,8 +133,6 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
};
}
getSuccessMessage() {
return new Row(
children: <Widget>[

View File

@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:async';
import 'package:checker/base/base_screen.dart';
import 'package:checker/base/base_state.dart';
@@ -42,8 +43,7 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
/// Список виджетов, автоматически прокручиваемый вверх при открытии клавиатуры.
@override
Widget getScreenContent() {
return new Container(
child: new ListView(children: <Widget>[
return new Container(child: new ListView(children: <Widget>[
new Column(children: <Widget>[
getLogo(),
getHintLabel(),
@@ -88,12 +88,12 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
_registerShop() {
setState(() {
loading = true;
_register();
register();
});
}
/// Получение от платформы id установки, формирование запроса на получение токена, сохранение токена.
_register() async {
register() async {
if (await platform.invokeMethod('isOnline')) {
String posID = await helper.getPosID();
@@ -110,8 +110,12 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
if (response.statusCode == 201) {
helper.createSession(merchantID, posID, parsedMap['token']).then((_) {
pushRouteReplacement(
context, new FinishRegistrationScreen(helper, app));
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<bool>(builder: (BuildContext context) => new FinishRegistrationScreen(helper, app), fullscreenDialog: true);
Navigator.of(context).pushReplacement(route).then((b) {
print('finish registration closed: $b');
});
});
});
} else {
setState(() {

View File

@@ -83,7 +83,16 @@ class _SplashScreenState extends BaseState<SplashScreen> {
// В случае, если в приложении отсутствует токен,
// необходимо запустить регистрацию кассы.
if (token == null) {
pushRouteReplacement(context, new RegistrationScreen(helper, app));
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<bool>(
builder: (BuildContext context) => new RegistrationScreen(helper, app), fullscreenDialog: true);
Navigator.of(context).push(route).then((b) {
_initAndStartScanner(context, app, token, helper);
});
});
// pushRoute(context, new RegistrationScreen(helper, app));
} else {
if (await platform.invokeMethod('isOnline')) {
getCheckTokenStatusRequest(token).then((statusResponse) {
@@ -100,7 +109,6 @@ class _SplashScreenState extends BaseState<SplashScreen> {
/// Если токен не активен, попробовать создать его еще раз.
handleStatusResponse(var statusResponse, SqliteHelper helper) async {
int code = statusResponse.statusCode;
if (code == 404) {
helper.clear().then((result) {
pushRouteReplacement(context, new RegistrationScreen(helper, app));
@@ -191,7 +199,14 @@ class _SplashScreenState extends BaseState<SplashScreen> {
} else if (call.method == 'faq') {
faq(helper, app, context, true);
} else if (call.method == 'settings') {
pushRoute(context, new SettingsScreen(helper, app, true));
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<bool>(
builder: (BuildContext context) => new SettingsScreen(helper, app, true), fullscreenDialog: true);
Navigator.of(context).push(route).then((b) {
print('purchase closed: $b');
_initAndStartScanner(context, app, token, helper);
});
});
} else {
String userString;
@@ -254,5 +269,4 @@ class _SplashScreenState extends BaseState<SplashScreen> {
return null;
}
}
}
}