На экране проведения покупки правильно обрабатывается сумма покупки, передается на экран подтверждения

This commit is contained in:
Ivan Murashov
2017-07-24 18:07:30 +03:00
parent 355c05cf06
commit 080c7ec471
9 changed files with 200 additions and 140 deletions

View File

@@ -14,7 +14,7 @@ class PurchaseScreen extends StatefulWidget {
class PurchaseScreenState<T> extends BaseState<T> {
String _sum = "1234.00";
String integerPart = '', fractionalPart = '';
@override String getTitle() {
return "Проведение покупки";
@@ -27,7 +27,7 @@ class PurchaseScreenState<T> extends BaseState<T> {
@overide getMenuButtons(BuildContext context) {
return <Widget>[
new IconButton(icon: new Icon(Icons.help_outline), onPressed: () {}),
new IconButton(icon: new Image.asset(logout_png, height: 20.0, width: 20.0), onPressed: () => logout(context))
new IconButton(icon: new Image.asset(logout_png, height: iconHeight, width: iconHeight), onPressed: () => logout(context))
];
}
@@ -40,47 +40,53 @@ class PurchaseScreenState<T> extends BaseState<T> {
getValueWithTitle('Вознаграждение', '100%'),
getHintLabel(),
getDecoratedTextWidget(),
buildButton(new EdgeInsets.only(top: 36.0, left: 70.0, right: 70.0), buildRaisedButton(context, 'ЗАВЕРШИТЬ ПОКУПКУ', () => _purchase(context))),
buildButton(new EdgeInsets.only(top: 24.0, left: 70.0, right: 70.0), buildFlatButton(context, 'СКАНИРОВАТЬ', primaryColor))])
buildButton(new EdgeInsets.only(top: 36.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildRaisedButton(context, 'ЗАВЕРШИТЬ ПОКУПКУ', () => _purchase(context))),
buildButton(new EdgeInsets.only(top: 24.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildFlatButton(context, 'СКАНИРОВАТЬ', primaryColor))])
].reversed.toList()));
}
Widget getValueWithTitle(String title, String value) {
return new Container(padding: new EdgeInsets.only(left: verticalMargin, right: verticalMargin, top: 18.0),
child: new Column(children: <Widget>[
new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[new Text(title, textAlign: TextAlign.left, style: new TextStyle(color: greyTextColor, fontSize: 14.0))]),
new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[new Text(value, textAlign: TextAlign.left, style: new TextStyle(color: Colors.black, fontSize: 20.0))])
]));
@override Color getTextFilledBackground() {
return Colors.white;
}
Widget buildButton(EdgeInsets margin, Widget widget) {
return new Container(margin: margin, height: 48.0, child: new Row(children: <Widget>[new Expanded(child: widget)]));
}
Widget buildRaisedButton(BuildContext context, String text, VoidCallback onPressed) {
return new RaisedButton(child: new Text(text,
style: new TextStyle(color: Colors.white)),
onPressed: onPressed,
color: primaryColor);
/// Смена состояния экрана при изменении текста в поле ввода.
@override handleUserInput(String tmpString) {
setState(() {
tmpString = tmpString.replaceAll('-', '');
tmpString = tmpString.replaceAll(', ', '');
print(tmpString);
if (tmpString.contains('.')) {
int dotIndex = tmpString.indexOf('.');
integerPart = tmpString.substring(0, dotIndex);
fractionalPart = tmpString.substring(dotIndex + 1, tmpString.length);
if (fractionalPart.length > 2) {
fractionalPart = fractionalPart.substring(0, 2);
}
controller.text = '${integerPart}.${fractionalPart}';
} else {
integerPart = tmpString;
controller.text = tmpString;
}
textFieldValue = controller.text;
});
}
Widget buildFlatButton(BuildContext context, String title, Color textColor) {
return new Container(height: 48.0, child: new FlatButton(child: new Text(title,
style: new TextStyle(color: textColor)),
onPressed: () => startScanner(context)),
decoration: _getDecoraionForScanButton());
}
_buildSum() {
String temporaryInteger = integerPart;
String temporaryFractional = fractionalPart;
_getDecoraionForScanButton() {
return new BoxDecoration(
border: new Border.all(color: primaryColor, width: 1.0),
borderRadius: new BorderRadius.all(new Radius.circular(4.0)));
while (temporaryFractional.length < 2) {
temporaryFractional = temporaryFractional + '0';
}
return temporaryInteger + '.' + temporaryFractional;
}
_purchase(BuildContext context) {
String val = _buildSum();
showDialog(context: context, child: new AlertDialog(
title: new Text('Подтверждение'),
content: new Text('Вы подтверждаете покупку на ${_sum} руб?'),
content: new Text('Вы подтверждаете покупку на ${val} руб?'),
actions: <Widget>[
new FlatButton(
child: new Text('Нет'),
@@ -89,16 +95,11 @@ class PurchaseScreenState<T> extends BaseState<T> {
},
),
new FlatButton(
child: new Text('Дат'),
child: new Text('Да'),
onPressed: () {
pushRoute(context, new PurchaseSuccessScreen());
pushRoute(context, new PurchaseSuccessScreen(val));
},
)
]));
print('purchase');
}
_register(BuildContext context) async {
}
}