issue 10305, final

This commit is contained in:
Semyon Babushkin
2017-10-30 19:53:17 +03:00
parent e5b7a6b875
commit 2bf999ce48
7 changed files with 54 additions and 24 deletions

View File

@@ -51,6 +51,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
bool purchaseInProgress = false;
Map user;
String card = '';
String flavor = '';
String loyalty = '';
String bonus = '';
bool dataLoaded = false;
@@ -74,8 +75,9 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
widgets.add(getInputField()); // Нельзя добавить еще одно поле таким же способом
widgets.add(getBonusInputField());
if (this.flavor != 'autobonus') {
widgets.add(getBonusInputField());
}
widgets.add(wrapButton(getScreenMargins(36.0), getCompleteButton()));
widgets.add(wrapButton(
@@ -155,6 +157,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
borderRadius: new BorderRadius.all(new Radius.circular(4.0))));
}
@override
String getTitle() {
return StringsLocalization.carryingPurchase();
@@ -186,11 +190,13 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
requestLoyalty(String url) async {
bool showBonus = await platform.invokeMethod('showBonus');
String flavor = await platform.invokeMethod('getFlavor');
if (await platform.invokeMethod('isOnline') && !this.dataLoaded) {
getLoyaltyRequest(url, helper).then((response) {
print(response);
this.dataLoaded = true;
setState(() {
this.flavor = flavor;
setBonuses(JSON.decode(response.body), showBonus );
});
}).catchError((error) {
@@ -258,6 +264,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
new FlatButton(
child: new Text(StringsLocalization.yes()),
onPressed: () {
Navigator.of(context).pop();
purchase(val);
},
)
@@ -303,32 +310,21 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
body['bonus_payment'] = bonusController.text;
}
print(body['bonus_payment']);
var purchaseResponse;
Map purchase;
try {
purchaseResponse = await getPurchaseRequest(user['purchases_url'], body, token);
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());
}
Navigator.of(context).pop();
if (purchase.containsKey('errors')) {
List<String> errors = purchase['errors'];
Scaffold
.of(context)
.showSnackBar(new SnackBar(content: new Text(errors[0])));
purchaseInProgress = false;
apiErrorAlert(errors[0]);
} else {
var couponsResponse;

View File

@@ -64,9 +64,7 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
platform.invokeMethod('getFlavor').then((flavor) {
setState(() {
this.flavor = flavor;
// if (showBonus == true) {
//
// }
if (this.details['sum_bonus'] is String) {
String regexString = r'(\d+) начислено, (\d+).*';
RegExp regExp = new RegExp(regexString);
@@ -80,7 +78,6 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
if (this.details['sum_bonus'] is int) {
this.bonusPlus = this.details['sum_bonus'];
//bonusMinus = this.details['sum_bonus'];
}
});
});
@@ -108,11 +105,16 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
}
// widgetList.add( new Expanded(child: new Center()));
this.coupons.forEach((couponItem) {
widgetList.add(getCoupons(couponItem));
});
if (this.coupons.length > 0) {
widgetList.add(getItemTitle(StringsLocalization.couponsUsed()));
this.coupons.forEach((couponItem) {
widgetList.add(getCoupons(couponItem));
});
}
widgetList.add(wrapButton(getScreenMargins(74.0), getScanButton()));
widgetList.add(wrapButton(getScreenMargins(174.0), getScanButton()));
return new ListView.builder(
itemBuilder: (BuildContext context, int index) => widgetList[index],
@@ -139,12 +141,16 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
}
getCoupons(couponItem) {
String title = couponItem['offer_name'];
if (title.length == 0) {
title = couponItem['coupon_condition'].substring(0,30) + " ...";
}
return new Container(
margin: new EdgeInsets.only(left: 5.0, right: 5.0, top: 5.0),
child: new Card(
child: new ExpansionTile(
title: new Text(
couponItem['offer_name'],
title,
style: Theme.of(context).textTheme.button.copyWith(
fontWeight: FontWeight.bold,
color: faqTitlesColor