purchase screen coupons list final
This commit is contained in:
@@ -91,8 +91,8 @@ android {
|
|||||||
buildConfigField "String", "supportUrl", "\"http://yandex.ru/\""
|
buildConfigField "String", "supportUrl", "\"http://yandex.ru/\""
|
||||||
buildConfigField "String", "endpoint", "\"https://pos-api-int.dinect.com/20130701/\""
|
buildConfigField "String", "endpoint", "\"https://pos-api-int.dinect.com/20130701/\""
|
||||||
buildConfigField "String", "appToken", "\"9fec83cdca38c357e6b65dbb17514cdd36bf2a08\""
|
buildConfigField "String", "appToken", "\"9fec83cdca38c357e6b65dbb17514cdd36bf2a08\""
|
||||||
buildConfigField "String", "appTitle", "\"Autobonus\""
|
buildConfigField "String", "appTitle", "\"Autobonus (develop)\""
|
||||||
buildConfigField "boolean", "showBonus", "false"
|
buildConfigField "boolean", "showBonus", "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,17 @@ getPurchaseRequest(String endpoint, Map body, String token) async {
|
|||||||
return httpClient.post(endpoint, body: body, headers: headers);
|
return httpClient.post(endpoint, body: body, headers: headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCouponsRequest(String endpoint, String token) async {
|
||||||
|
|
||||||
|
var headers = {
|
||||||
|
'DM-Authorization': 'dmapptoken ${await getToken()}',
|
||||||
|
'Authorization': 'dmtoken ${token}',
|
||||||
|
'Accept-Language': Intl.defaultLocale
|
||||||
|
};
|
||||||
|
|
||||||
|
return httpClient.get(endpoint, headers: headers);
|
||||||
|
}
|
||||||
|
|
||||||
getEndpoint() async {
|
getEndpoint() async {
|
||||||
return await platform.invokeMethod('getEndpoint');
|
return await platform.invokeMethod('getEndpoint');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,8 +219,9 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
purchaseInProgress = true;
|
purchaseInProgress = true;
|
||||||
|
|
||||||
String token = await helper.getToken();
|
String token = await helper.getToken();
|
||||||
helper.getMerchantID().then((result) {
|
var result = await helper.getMerchantID();
|
||||||
helper.getCurrency().then((currency) {
|
var currency = await helper.getCurrency();
|
||||||
|
|
||||||
var body = {
|
var body = {
|
||||||
'doc_id': result,
|
'doc_id': result,
|
||||||
'curr_iso_code': currency.toString(),
|
'curr_iso_code': currency.toString(),
|
||||||
@@ -228,19 +229,38 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
'sum_total': sumTotal
|
'sum_total': sumTotal
|
||||||
};
|
};
|
||||||
|
|
||||||
getPurchaseRequest(user['purchases_url'], body, token)
|
var purchaseResponse;
|
||||||
.then((response) {
|
|
||||||
print(response.body);
|
try {
|
||||||
Map parsedMap = JSON.decode(response.body);
|
purchaseResponse = await getPurchaseRequest(user['purchases_url'], body, token);
|
||||||
|
print(purchaseResponse.body);
|
||||||
|
} catch(error) {
|
||||||
|
purchaseInProgress = false;
|
||||||
|
print(error.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Map purchase = JSON.decode(purchaseResponse.body);
|
||||||
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
|
||||||
if (parsedMap.containsKey('errors')) {
|
if (purchase.containsKey('errors')) {
|
||||||
List<String> errors = parsedMap['errors'];
|
List<String> errors = purchase['errors'];
|
||||||
Scaffold
|
Scaffold
|
||||||
.of(context)
|
.of(context)
|
||||||
.showSnackBar(new SnackBar(content: new Text(errors[0])));
|
.showSnackBar(new SnackBar(content: new Text(errors[0])));
|
||||||
} else {
|
} else {
|
||||||
|
var couponsResponse;
|
||||||
|
|
||||||
|
try {
|
||||||
|
couponsResponse = await getCouponsRequest(purchase['coupons_url'], token);
|
||||||
|
print(couponsResponse.body);
|
||||||
|
} catch(error) {
|
||||||
|
purchaseInProgress = false;
|
||||||
|
print(error.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Map coupons = JSON.decode(couponsResponse.body);
|
||||||
|
|
||||||
pushRouteReplacement(
|
pushRouteReplacement(
|
||||||
context,
|
context,
|
||||||
new PurchaseSuccessScreen(
|
new PurchaseSuccessScreen(
|
||||||
@@ -248,15 +268,11 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
user['first_name'] == null ? '' : user['first_name'],
|
user['first_name'] == null ? '' : user['first_name'],
|
||||||
helper,
|
helper,
|
||||||
app,
|
app,
|
||||||
parsedMap
|
purchase,
|
||||||
));
|
coupons['results']
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}).catchError((error) {
|
|
||||||
purchaseInProgress = false;
|
|
||||||
print(error.toString());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,46 +8,40 @@ import 'package:flutter/material.dart';
|
|||||||
/// Экран проведения покупки.
|
/// Экран проведения покупки.
|
||||||
class PurchaseSuccessScreen extends StatefulWidget {
|
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 val;
|
||||||
final String name;
|
final String name;
|
||||||
final String app;
|
final String app;
|
||||||
final SqliteHelper helper;
|
final SqliteHelper helper;
|
||||||
final Map details;
|
final Map details;
|
||||||
|
final List<Map> coupons;
|
||||||
|
|
||||||
@override State createState() =>
|
@override State createState() =>
|
||||||
new PurchaseSuccessScreenState(val, name, helper, app, details);
|
new PurchaseSuccessScreenState(val, name, helper, app, details, coupons);
|
||||||
}
|
}
|
||||||
|
|
||||||
class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
|
class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
|
||||||
|
|
||||||
PurchaseSuccessScreenState(
|
PurchaseSuccessScreenState(
|
||||||
String sum, String username, SqliteHelper helper,
|
String sum, String username, SqliteHelper helper,
|
||||||
String app, Map details
|
String app, Map details, List<Map> coupons
|
||||||
){
|
){
|
||||||
this.sum = sum;
|
this.sum = sum;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.helper = helper;
|
this.helper = helper;
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.details = details;
|
this.details = details;
|
||||||
|
this.coupons = coupons;
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String sum, username;
|
String sum, username;
|
||||||
Map details;
|
Map details;
|
||||||
|
List<Map> coupons;
|
||||||
int bonusPlus = 0;
|
int bonusPlus = 0;
|
||||||
int bonusMinus = 0;
|
int bonusMinus = 0;
|
||||||
int currency;
|
int currency;
|
||||||
|
bool showBonus;
|
||||||
|
|
||||||
@override String getTitle() {
|
@override String getTitle() {
|
||||||
return StringsLocalization.carryingPurchase();
|
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();
|
return getMainWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override Widget getScreenContent() {
|
@override Widget getScreenContent() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List <Widget> widgetList = <Widget>[];
|
List <Widget> widgetList = <Widget>[];
|
||||||
widgetList.add(getValueWithDescription(StringsLocalization.buyer(), username));
|
widgetList.add(getValueWithDescription(StringsLocalization.buyer(), username));
|
||||||
widgetList.add(getSuccessMessage());
|
widgetList.add(getSuccessMessage());
|
||||||
|
if (showBonus == true) {
|
||||||
if (bonusPlus > 0) {
|
if (bonusPlus > 0) {
|
||||||
widgetList.add(getValueWithDescription(StringsLocalization.bonusPlus(), bonusPlus.toString()));
|
widgetList.add(getValueWithDescription(StringsLocalization.bonusPlus(), bonusPlus.toString()));
|
||||||
}
|
}
|
||||||
if (bonusMinus > 0) {
|
if (bonusMinus > 0) {
|
||||||
widgetList.add(getValueWithDescription(StringsLocalization.bonusMinus(), bonusMinus.toString()));
|
widgetList.add(getValueWithDescription(StringsLocalization.bonusMinus(), bonusMinus.toString()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
widgetList.add(getValueWithDescription(StringsLocalization.discountRate(), '${details['discount']}%'));
|
widgetList.add(getValueWithDescription(StringsLocalization.discountRate(), '${details['discount']}%'));
|
||||||
widgetList.add(getValueWithDescription(StringsLocalization.discountSum(), '${details['sum_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()));
|
widgetList.add(wrapButton(getScreenMargins(74.0), getScanButton()));
|
||||||
|
|
||||||
return new Column(
|
return new ListView.builder(
|
||||||
children: widgetList
|
itemBuilder: (BuildContext context, int index) => widgetList[index],
|
||||||
|
itemCount: widgetList.length
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getScreenMargins(double bottom) {
|
getScreenMargins(double bottom) {
|
||||||
@@ -109,66 +134,23 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCoupons(couponItem) {
|
||||||
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);
|
|
||||||
|
|
||||||
return new Container(
|
return new Container(
|
||||||
margin: margin,
|
margin: new EdgeInsets.only(left: 5.0, right: 5.0, top: 5.0),
|
||||||
child: new Card(
|
child: new Card(
|
||||||
child: new ExpansionTile(
|
child: new ExpansionTile(
|
||||||
//key: new PageStorageKey<Entry>(root),
|
|
||||||
title: new Text(
|
title: new Text(
|
||||||
'Coupons',
|
couponItem['offer_name'],
|
||||||
style: titleStyle
|
style: Theme.of(context).textTheme.button.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: faqTitlesColor
|
||||||
|
)
|
||||||
),
|
),
|
||||||
children: [
|
children: [
|
||||||
new Container(
|
new Container(
|
||||||
margin: margin,
|
margin: new EdgeInsets.only(left: 20.0, right: 20.0),
|
||||||
padding: new EdgeInsets.only(top: 12.0, bottom: 20.0),
|
padding: new EdgeInsets.only(top: 0.0, bottom: 10.0),
|
||||||
child: new Text('Coupons'),
|
child: new Text(couponItem['coupon_condition']),
|
||||||
decoration: new BoxDecoration(
|
|
||||||
border: new Border(
|
|
||||||
top: new BorderSide(
|
|
||||||
color: greyTextColor,
|
|
||||||
width: 0.5
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user