174 lines
4.8 KiB
Dart
174 lines
4.8 KiB
Dart
import 'package:checker/base/base_state.dart';
|
|
import 'package:checker/common.dart';
|
|
import 'package:checker/consts.dart';
|
|
import 'package:checker/db.dart';
|
|
import 'package:checker/strings.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// Экран проведения покупки.
|
|
class PurchaseSuccessScreen extends StatefulWidget {
|
|
|
|
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, coupons);
|
|
}
|
|
|
|
class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
|
|
|
|
PurchaseSuccessScreenState(
|
|
String sum, String username, SqliteHelper helper,
|
|
String app, Map details, List<Map> coupons
|
|
){
|
|
this.sum = sum;
|
|
this.username = username;
|
|
this.helper = helper;
|
|
this.app = app;
|
|
this.details = details;
|
|
this.coupons = coupons;
|
|
}
|
|
|
|
String sum, username;
|
|
Map details;
|
|
List<Map> coupons;
|
|
int bonusPlus = 0;
|
|
int bonusMinus = 0;
|
|
int currency;
|
|
bool showBonus;
|
|
String flavor;
|
|
|
|
@override String getTitle() {
|
|
return StringsLocalization.carryingPurchase();
|
|
}
|
|
|
|
@override String getHintString() {
|
|
return null;
|
|
}
|
|
|
|
@override Widget build(BuildContext context) {
|
|
if (currency == null) {
|
|
helper.getCurrency().then((currency) {
|
|
setState(() {
|
|
this.currency = currency;
|
|
});
|
|
});
|
|
}
|
|
if (this.flavor == null) {
|
|
platform.invokeMethod('getFlavor').then((flavor) {
|
|
setState(() {
|
|
this.flavor = flavor;
|
|
|
|
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'];
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
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 (this.flavor != 'autobonus') {
|
|
widgetList.add(getValueWithDescription(StringsLocalization.discountRate(), '${details['discount']}%'));
|
|
widgetList.add(getValueWithDescription(StringsLocalization.discountSum(), '${details['sum_discount']}'));
|
|
}
|
|
|
|
// widgetList.add( new Expanded(child: new Center()));
|
|
if (this.coupons.length > 0) {
|
|
widgetList.add(getItemTitle(StringsLocalization.couponsUsed()));
|
|
this.coupons.forEach((couponItem) {
|
|
widgetList.add(getItemToggle(
|
|
couponItem['offer_name'],
|
|
couponItem['coupon_condition']
|
|
));
|
|
});
|
|
}
|
|
|
|
widgetList.add(wrapButton(getScreenMargins(174.0), getScanButton()));
|
|
|
|
return new ListView.builder(
|
|
itemBuilder: (BuildContext context, int index) => widgetList[index],
|
|
itemCount: widgetList.length
|
|
);
|
|
|
|
}
|
|
|
|
getScreenMargins(double bottom) {
|
|
double side = 42.0;
|
|
return new EdgeInsets.only(bottom: bottom, left: side, right: side);
|
|
}
|
|
|
|
getScanButton() {
|
|
String title = StringsLocalization.scan();
|
|
return buildRaisedButton(title, () => startScanner(context, app, helper));
|
|
}
|
|
|
|
|
|
ExpansionPanelHeaderBuilder get headerBuilder {
|
|
return (BuildContext context, bool isExpanded) {
|
|
return new Text('Purchase details');
|
|
};
|
|
}
|
|
|
|
|
|
|
|
getSuccessMessage() {
|
|
return new Row(
|
|
children: <Widget>[
|
|
new Expanded(child: new Container(
|
|
margin: new EdgeInsets.only(top: 20.0), height: 64.0,
|
|
decoration: new BoxDecoration(color: greenBackground),
|
|
child: new Center(
|
|
child: new Text(
|
|
getMessageTitle(), textAlign: TextAlign.center,
|
|
style: new TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: tokenActiveTextColor
|
|
)
|
|
)
|
|
)
|
|
))
|
|
]);
|
|
}
|
|
|
|
getMessageTitle() {
|
|
if (currency != null) {
|
|
return StringsLocalization.purchaseCompleted(sum, currency);
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
}
|