purchase screen coupons list final

This commit is contained in:
Semyon Babushkin
2017-10-11 18:32:59 +03:00
parent 3f9afd5569
commit 7b20747157
4 changed files with 123 additions and 114 deletions

View File

@@ -8,46 +8,40 @@ import 'package:flutter/material.dart';
/// Экран проведения покупки.
class PurchaseSuccessScreen extends StatefulWidget {
PurchaseSuccessScreen(this.val, this.name, this.helper, this.app, this.details);
PurchaseSuccessScreen(this.val, this.name, this.helper, this.app, this.details, this.coupons);
final String val;
final String name;
final String app;
final SqliteHelper helper;
final Map details;
final List<Map> coupons;
@override State createState() =>
new PurchaseSuccessScreenState(val, name, helper, app, details);
new PurchaseSuccessScreenState(val, name, helper, app, details, coupons);
}
class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
PurchaseSuccessScreenState(
String sum, String username, SqliteHelper helper,
String app, Map details
String app, Map details, List<Map> coupons
){
this.sum = sum;
this.username = username;
this.helper = helper;
this.app = app;
this.details = details;
String regexString = r'(\d+) начислено, (\d+).*';
RegExp regExp = new RegExp(regexString);
var matches = regExp.allMatches(this.details['sum_bonus']);
if(matches.length != 0) {
var match = matches.elementAt(0); // => extract the first (and only) match
bonusPlus = int.parse(match.group(1));
bonusMinus = int.parse(match.group(2));
}
this.coupons = coupons;
}
String sum, username;
Map details;
List<Map> coupons;
int bonusPlus = 0;
int bonusMinus = 0;
int currency;
bool showBonus;
@override String getTitle() {
return StringsLocalization.carryingPurchase();
@@ -65,31 +59,62 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
});
});
}
if (showBonus == null) {
platform.invokeMethod('showBonus').then((showBonus) {
setState(() {
this.showBonus = showBonus;
if (showBonus == true) {
if (this.details['sum_bonus'] is String) {
String regexString = r'(\d+) начислено, (\d+).*';
RegExp regExp = new RegExp(regexString);
var matches = regExp.allMatches(this.details['sum_bonus']);
if(matches.length != 0) {
var match = matches.elementAt(0); // => extract the first (and only) match
this.bonusPlus = int.parse(match.group(1));
this.bonusMinus = int.parse(match.group(2));
}
}
if (this.details['sum_bonus'] is int) {
this.bonusPlus = this.details['sum_bonus'];
//bonusMinus = this.details['sum_bonus'];
}
}
});
});
}
return getMainWidget();
}
@override Widget getScreenContent() {
List <Widget> widgetList = <Widget>[];
widgetList.add(getValueWithDescription(StringsLocalization.buyer(), username));
widgetList.add(getSuccessMessage());
if (bonusPlus > 0) {
widgetList.add(getValueWithDescription(StringsLocalization.bonusPlus(), bonusPlus.toString()));
}
if (bonusMinus > 0) {
widgetList.add(getValueWithDescription(StringsLocalization.bonusMinus(), bonusMinus.toString()));
if (showBonus == true) {
if (bonusPlus > 0) {
widgetList.add(getValueWithDescription(StringsLocalization.bonusPlus(), bonusPlus.toString()));
}
if (bonusMinus > 0) {
widgetList.add(getValueWithDescription(StringsLocalization.bonusMinus(), bonusMinus.toString()));
}
}
widgetList.add(getValueWithDescription(StringsLocalization.discountRate(), '${details['discount']}%'));
widgetList.add(getValueWithDescription(StringsLocalization.discountSum(), '${details['sum_discount']}'));
widgetList.add(getCoupons());
widgetList.add( new Expanded(child: new Center()));
// widgetList.add( new Expanded(child: new Center()));
this.coupons.forEach((couponItem) {
widgetList.add(getCoupons(couponItem));
});
widgetList.add(wrapButton(getScreenMargins(74.0), getScanButton()));
return new Column(
children: widgetList
return new ListView.builder(
itemBuilder: (BuildContext context, int index) => widgetList[index],
itemCount: widgetList.length
);
}
getScreenMargins(double bottom) {
@@ -109,66 +134,23 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
};
}
getCoupons() {
EdgeInsets margin = new EdgeInsets.only(left: 20.0, right: 20.0);
TextStyle titleStyle = Theme.of(context).textTheme.button.copyWith(
fontWeight: FontWeight.bold,
color: faqTitlesColor
);
final List<Widget> detailsRows = <Widget>[];
// this.details.forEach((key, value) => detailsRows.add(
// new Text(key)
// new Row(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: <Widget>[
// new Text('1'),
// new Text('2'),
//
// new Container(
// margin: const EdgeInsets.only(right: 16.0),
// child: new CircleAvatar(child: new Text('D')),
// ),
// new Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: <Widget>[
// new Text(key, style: Theme.of(context).textTheme.subhead),
// new Container(
// margin: const EdgeInsets.only(top: 0.5),
// child: new Text(key)
// )
// ]
// )
// ],
// )
// ));
print(detailsRows.length);
getCoupons(couponItem) {
return new Container(
margin: margin,
margin: new EdgeInsets.only(left: 5.0, right: 5.0, top: 5.0),
child: new Card(
child: new ExpansionTile(
//key: new PageStorageKey<Entry>(root),
title: new Text(
'Coupons',
style: titleStyle
couponItem['offer_name'],
style: Theme.of(context).textTheme.button.copyWith(
fontWeight: FontWeight.bold,
color: faqTitlesColor
)
),
children: [
new Container(
margin: margin,
padding: new EdgeInsets.only(top: 12.0, bottom: 20.0),
child: new Text('Coupons'),
decoration: new BoxDecoration(
border: new Border(
top: new BorderSide(
color: greyTextColor,
width: 0.5
)
)
)
margin: new EdgeInsets.only(left: 20.0, right: 20.0),
padding: new EdgeInsets.only(top: 0.0, bottom: 10.0),
child: new Text(couponItem['coupon_condition']),
)
]
)