Purchase screen

This commit is contained in:
Ivan Murashov
2018-05-20 13:47:17 +03:00
parent d9400a3df9
commit beb3732b63

View File

@@ -69,8 +69,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
Widget getScreenContent() { Widget getScreenContent() {
List<Widget> widgetList = []; List<Widget> widgetList = [];
widgetList.add(getValueWithDescription( widgetList.add(getValueWithDescription(
StringsLocalization.buyer(), StringsLocalization.buyer(),
user['first_name'] == null ? '' : user['first_name'] user['first_name'] == null ? '' : user['first_name']
)); ));
widgetList.add(getValueWithDescription(StringsLocalization.card(), card)); widgetList.add(getValueWithDescription(StringsLocalization.card(), card));
@@ -115,14 +115,18 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
widgetList.add(wrapButton(getScreenMargins(36.0), getCompleteButton())); widgetList.add(wrapButton(getScreenMargins(36.0), getCompleteButton()));
widgetList.add(wrapButton( widgetList.add(wrapButton(
getScreenMargins(24.0), getScreenMargins(24.0),
getScanButton( getScanButton(
context, context,
StringsLocalization.scan(), StringsLocalization.scan(),
Resources.getPrimaryColor(app) Resources.getPrimaryColor(app)
) )
)); ));
if (this.coupons.length == 0) {
widgetList.add(new Container(height: 50.0,));
}
listView = new ListView(children: widgetList, controller: scrollController); listView = new ListView(children: widgetList, controller: scrollController);
return listView; return listView;
} }
@@ -178,19 +182,19 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
getCompleteButton() { getCompleteButton() {
return buildRaisedButton( return buildRaisedButton(
StringsLocalization.completePurchase(), () => onPurchaseClick()); StringsLocalization.completePurchase(), () => onPurchaseClick());
} }
Widget getScanButton(BuildContext context, String title, Color textColor) { Widget getScanButton(BuildContext context, String title, Color textColor) {
return new Container( return new Container(
height: buttonHeight, height: buttonHeight,
child: new FlatButton( child: new FlatButton(
child: new Text(title, style: new TextStyle(color: textColor)), child: new Text(title, style: new TextStyle(color: textColor)),
onPressed: () => restartScanner()), onPressed: () => restartScanner()),
decoration: new BoxDecoration( decoration: new BoxDecoration(
border: new Border.all( border: new Border.all(
color: Resources.getButtonColor(app), width: 1.0), color: Resources.getButtonColor(app), width: 1.0),
borderRadius: new BorderRadius.all(new Radius.circular(4.0)))); borderRadius: new BorderRadius.all(new Radius.circular(4.0))));
} }
@override @override
@@ -208,8 +212,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
return new TextField( return new TextField(
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
decoration: new InputDecoration.collapsed( decoration: new InputDecoration.collapsed(
hintText: getHintString(), hintText: getHintString(),
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)), hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
controller: controller, controller: controller,
focusNode: sumFocusNode, focusNode: sumFocusNode,
onSubmitted: (String text) { onSubmitted: (String text) {
@@ -253,10 +257,10 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
// TODO: Переделать, если потребуется // TODO: Переделать, если потребуется
String _cleanupNumber(String text) { String _cleanupNumber(String text) {
String tmp = text String tmp = text
.replaceAll(' ', '') .replaceAll(' ', '')
.replaceAll('-', '') .replaceAll('-', '')
.replaceAll(',', '.') .replaceAll(',', '.')
.replaceAll('..', '.'); .replaceAll('..', '.');
while (tmp.indexOf('..') != -1) { while (tmp.indexOf('..') != -1) {
tmp = tmp.replaceAll('..', '.'); tmp = tmp.replaceAll('..', '.');
@@ -293,28 +297,28 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
helper.getCurrency().then((currency) { helper.getCurrency().then((currency) {
print(currency.toString()); print(currency.toString());
showDialog( showDialog(
context: context, context: context,
child: new AlertDialog( child: new AlertDialog(
title: new Text(StringsLocalization.confirmation()), title: new Text(StringsLocalization.confirmation()),
content: content:
new Text( new Text(
StringsLocalization.confirmPurchase(val, currency) StringsLocalization.confirmPurchase(val, currency)
), ),
actions: <Widget>[ actions: <Widget>[
new FlatButton( new FlatButton(
child: new Text(StringsLocalization.no()), child: new Text(StringsLocalization.no()),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),
new FlatButton( new FlatButton(
child: new Text(StringsLocalization.yes()), child: new Text(StringsLocalization.yes()),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
purchase(val); purchase(val);
}, },
) )
])); ]));
}); });
} }
@@ -425,7 +429,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
this.loyalty = '${user['discount']}%'; this.loyalty = '${user['discount']}%';
} else { } else {
double loyaltyVal = (double.parse(bonuses['amount_to_bonus'][1]) / double loyaltyVal = (double.parse(bonuses['amount_to_bonus'][1]) /
bonuses['amount_to_bonus'][0]) * 100; bonuses['amount_to_bonus'][0]) * 100;
this.loyalty = '${loyaltyVal.toStringAsFixed(0)}%'; this.loyalty = '${loyaltyVal.toStringAsFixed(0)}%';
} }
@@ -448,6 +452,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
// TODO: Удалить дублирующийся код. // TODO: Удалить дублирующийся код.
void buildFocusNode() { void buildFocusNode() {
var pos = this.coupons.length > 0 ? 150.0 : 100.0;
sumFocusNode.addListener(() { sumFocusNode.addListener(() {
setState(() { setState(() {
@@ -456,7 +462,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
} }
if (sumFocusNode.hasFocus) { if (sumFocusNode.hasFocus) {
scrollController.animateTo(150.0, duration: new Duration(seconds: 1), curve: Curves.ease); scrollController.animateTo(pos, duration: new Duration(seconds: 1), curve: Curves.ease);
} }
}); });
@@ -470,7 +476,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
} }
if (bonusFocusNode.hasFocus) { if (bonusFocusNode.hasFocus) {
scrollController.animateTo(150.0, duration: new Duration(seconds: 1), curve: Curves.ease); scrollController.animateTo(pos, duration: new Duration(seconds: 1), curve: Curves.ease);
} }
}); });