From beb3732b63ee64b13a0c35fa1939507b76405bb1 Mon Sep 17 00:00:00 2001 From: Ivan Murashov Date: Sun, 20 May 2018 13:47:17 +0300 Subject: [PATCH] Purchase screen --- lib/screens/purchase.dart | 102 ++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/lib/screens/purchase.dart b/lib/screens/purchase.dart index 7552ec0..5dc4190 100644 --- a/lib/screens/purchase.dart +++ b/lib/screens/purchase.dart @@ -69,8 +69,8 @@ class PurchaseScreenState extends BaseState { Widget getScreenContent() { List widgetList = []; widgetList.add(getValueWithDescription( - StringsLocalization.buyer(), - user['first_name'] == null ? '' : user['first_name'] + StringsLocalization.buyer(), + user['first_name'] == null ? '' : user['first_name'] )); widgetList.add(getValueWithDescription(StringsLocalization.card(), card)); @@ -115,14 +115,18 @@ class PurchaseScreenState extends BaseState { widgetList.add(wrapButton(getScreenMargins(36.0), getCompleteButton())); widgetList.add(wrapButton( - getScreenMargins(24.0), - getScanButton( - context, - StringsLocalization.scan(), - Resources.getPrimaryColor(app) - ) + getScreenMargins(24.0), + getScanButton( + context, + StringsLocalization.scan(), + Resources.getPrimaryColor(app) + ) )); + if (this.coupons.length == 0) { + widgetList.add(new Container(height: 50.0,)); + } + listView = new ListView(children: widgetList, controller: scrollController); return listView; } @@ -178,19 +182,19 @@ class PurchaseScreenState extends BaseState { getCompleteButton() { return buildRaisedButton( - StringsLocalization.completePurchase(), () => onPurchaseClick()); + 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)), - onPressed: () => restartScanner()), - decoration: new BoxDecoration( - border: new Border.all( - color: Resources.getButtonColor(app), width: 1.0), - borderRadius: new BorderRadius.all(new Radius.circular(4.0)))); + height: buttonHeight, + child: new FlatButton( + child: new Text(title, style: new TextStyle(color: textColor)), + onPressed: () => restartScanner()), + decoration: new BoxDecoration( + border: new Border.all( + color: Resources.getButtonColor(app), width: 1.0), + borderRadius: new BorderRadius.all(new Radius.circular(4.0)))); } @override @@ -208,8 +212,8 @@ class PurchaseScreenState extends BaseState { return new TextField( keyboardType: TextInputType.number, decoration: new InputDecoration.collapsed( - hintText: getHintString(), - hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)), + hintText: getHintString(), + hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)), controller: controller, focusNode: sumFocusNode, onSubmitted: (String text) { @@ -253,10 +257,10 @@ class PurchaseScreenState extends BaseState { // TODO: Переделать, если потребуется String _cleanupNumber(String text) { String tmp = text - .replaceAll(' ', '') - .replaceAll('-', '') - .replaceAll(',', '.') - .replaceAll('..', '.'); + .replaceAll(' ', '') + .replaceAll('-', '') + .replaceAll(',', '.') + .replaceAll('..', '.'); while (tmp.indexOf('..') != -1) { tmp = tmp.replaceAll('..', '.'); @@ -293,28 +297,28 @@ class PurchaseScreenState extends BaseState { 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: [ - new FlatButton( - child: new Text(StringsLocalization.no()), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - new FlatButton( - child: new Text(StringsLocalization.yes()), - onPressed: () { - Navigator.of(context).pop(); - purchase(val); - }, - ) - ])); + context: context, + child: new AlertDialog( + title: new Text(StringsLocalization.confirmation()), + content: + new Text( + StringsLocalization.confirmPurchase(val, currency) + ), + actions: [ + new FlatButton( + child: new Text(StringsLocalization.no()), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + new FlatButton( + child: new Text(StringsLocalization.yes()), + onPressed: () { + Navigator.of(context).pop(); + purchase(val); + }, + ) + ])); }); } @@ -425,7 +429,7 @@ class PurchaseScreenState extends BaseState { this.loyalty = '${user['discount']}%'; } else { 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)}%'; } @@ -448,6 +452,8 @@ class PurchaseScreenState extends BaseState { // TODO: Удалить дублирующийся код. void buildFocusNode() { + var pos = this.coupons.length > 0 ? 150.0 : 100.0; + sumFocusNode.addListener(() { setState(() { @@ -456,7 +462,7 @@ class PurchaseScreenState extends BaseState { } 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 extends BaseState { } 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); } });