списание бонусов при покупке(часть)
This commit is contained in:
@@ -31,6 +31,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
/// (удаляет запрещенные символы до их отображаения).
|
||||
TextEditingController controller = new TextEditingController();
|
||||
|
||||
TextEditingController bonusController = new TextEditingController();
|
||||
|
||||
PurchaseScreenState(SqliteHelper helper, String app, String userString, String card) {
|
||||
this.user = JSON.decode(userString);
|
||||
this.card = card;
|
||||
@@ -62,13 +64,19 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
));
|
||||
widgets.add(getValueWithDescription(StringsLocalization.card(), card));
|
||||
|
||||
widgets.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
|
||||
|
||||
if (bonus.length > 0) {
|
||||
widgets.add(getValueWithDescription(StringsLocalization.bonus(), bonus));
|
||||
}
|
||||
|
||||
widgets.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
|
||||
widgets.add(getHintLabel());
|
||||
widgets.add(getInputField());
|
||||
|
||||
widgets.add(getInputField()); // Нельзя добавить еще одно поле таким же способом
|
||||
|
||||
widgets.add(getBonusInputField());
|
||||
|
||||
|
||||
widgets.add(wrapButton(getScreenMargins(36.0), getCompleteButton()));
|
||||
widgets.add(wrapButton(
|
||||
getScreenMargins(24.0),
|
||||
@@ -84,6 +92,47 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
]);
|
||||
}
|
||||
|
||||
getBonusInputField() {
|
||||
return new Column(
|
||||
children: <Widget>[
|
||||
new Container(
|
||||
margin: new EdgeInsets.only(
|
||||
left: verticalMargin,
|
||||
right: verticalMargin,
|
||||
top: verticalMargin
|
||||
),
|
||||
padding: getInputFieldContainerPadding(),
|
||||
decoration: getInputFieldContainerDecoration(),
|
||||
child: new TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: new InputDecoration.collapsed(
|
||||
hintText: StringsLocalization.bonusHint(),
|
||||
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
|
||||
controller: bonusController,
|
||||
onSubmitted: (String text) {
|
||||
setState(() {
|
||||
bonusController.text = text;
|
||||
});
|
||||
},
|
||||
textAlign: TextAlign.center,
|
||||
autofocus: true,
|
||||
)
|
||||
),
|
||||
new Container(
|
||||
margin: new EdgeInsets.only(
|
||||
top: 5.0
|
||||
),
|
||||
child: new Text(
|
||||
StringsLocalization.bonusExplanation(),
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: new TextStyle(color: greyTextColor, fontSize: 11.0),
|
||||
)
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
getScreenMargins(double top) {
|
||||
double side = 42.0;
|
||||
return new EdgeInsets.only(top: top, left: side, right: side);
|
||||
@@ -118,6 +167,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
|
||||
@override
|
||||
getTextWidget() {
|
||||
// ?? TODO переделать, т.к. позволяет иметь только одно поле ввода на странице
|
||||
return new TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: new InputDecoration.collapsed(
|
||||
@@ -195,7 +245,9 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
child: new AlertDialog(
|
||||
title: new Text(StringsLocalization.confirmation()),
|
||||
content:
|
||||
new Text(StringsLocalization.confirmPurchase(val, currency)),
|
||||
new Text(
|
||||
StringsLocalization.confirmPurchase(val, currency)
|
||||
),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text(StringsLocalization.no()),
|
||||
@@ -213,6 +265,24 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
apiErrorAlert(String errorText) {
|
||||
showDialog(
|
||||
context: context,
|
||||
child: new AlertDialog(
|
||||
//title: new Text(StringsLocalization.()),
|
||||
content: new Text(errorText),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text('Ok'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
purchase(String sumTotal) async {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
if (!purchaseInProgress) {
|
||||
@@ -229,17 +299,28 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
'sum_total': sumTotal
|
||||
};
|
||||
|
||||
if (bonusController.text.length > 0) {
|
||||
body['bonus_payment'] = bonusController.text;
|
||||
}
|
||||
|
||||
print(body['bonus_payment']);
|
||||
|
||||
var purchaseResponse;
|
||||
Map purchase;
|
||||
|
||||
try {
|
||||
purchaseResponse = await getPurchaseRequest(user['purchases_url'], body, token);
|
||||
print(purchaseResponse.body);
|
||||
purchase = JSON.decode(purchaseResponse.body);
|
||||
if (purchase['errors'] is List && purchase['errors'].length > 0) {
|
||||
print(purchase['errors'][0]);
|
||||
//Navigator.of(context).pop();
|
||||
apiErrorAlert(purchase['errors'][0]);
|
||||
}
|
||||
} catch(error) {
|
||||
purchaseInProgress = false;
|
||||
print(error.toString());
|
||||
}
|
||||
|
||||
Map purchase = JSON.decode(purchaseResponse.body);
|
||||
}
|
||||
|
||||
Navigator.of(context).pop();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user