initial commit

This commit is contained in:
Admin
2017-10-05 12:16:55 +03:00
parent d6a65b6de2
commit 23dce005b4
11 changed files with 238 additions and 20 deletions

View File

@@ -50,24 +50,37 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
Map user;
String card = '';
String loyalty = '';
String bonus = '';
bool dataLoaded = false;
@override
Widget getScreenContent() {
List<Widget> widgets = [];
widgets.add(getValueWithDescription(
StringsLocalization.buyer(),
user['first_name'] == null ? '' : user['first_name']
));
widgets.add(getValueWithDescription(StringsLocalization.card(), card));
if (bonus.length > 0) {
widgets.add(getValueWithDescription(StringsLocalization.bonus(), bonus));
}
widgets.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
widgets.add(getHintLabel());
widgets.add(getInputField());
widgets.add(wrapButton(getScreenMargins(36.0), getCompleteButton()));
widgets.add(wrapButton(
getScreenMargins(24.0),
getScanButton(
context,
StringsLocalization.scan(),
Resources.getPrimaryColor(app)
)
));
return new Column(children: <Widget>[
new Expanded(
child: new ListView(children: <Widget>[
getValueWithDescription(StringsLocalization.buyer(),
user['first_name'] == null ? '' : user['first_name']),
getValueWithDescription(StringsLocalization.card(), card),
getValueWithDescription(StringsLocalization.reward(), loyalty),
getHintLabel(),
getInputField(),
wrapButton(getScreenMargins(36.0), getCompleteButton()),
wrapButton(
getScreenMargins(24.0),
getScanButton(context, StringsLocalization.scan(),
Resources.getPrimaryColor(app)))
]))
child: new ListView(children: widgets))
]);
}
@@ -122,12 +135,13 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
}
requestLoyalty(String url) async {
print(url);
if (await platform.invokeMethod('isOnline')) {
bool showBonus = await platform.invokeMethod('showBonus');
if (await platform.invokeMethod('isOnline') && !this.dataLoaded) {
getLoyaltyRequest(url, helper).then((response) {
print(response);
this.dataLoaded = true;
setState(() {
setBonuses(JSON.decode(response.body));
setBonuses(JSON.decode(response.body), showBonus );
});
}).catchError((error) {
print(error.toString());
@@ -245,7 +259,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
}
}
void setBonuses(Map bonuses) {
void setBonuses(Map bonuses, bool showBonus) {
print('kifio ' + bonuses['type']);
if (bonuses['type'] == 'amount') {
this.loyalty = '${user['discount']}%';
@@ -254,6 +268,11 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
bonuses['amount_to_bonus'][0]) * 100;
this.loyalty = '${loyaltyVal.toStringAsFixed(0)}%';
}
if (showBonus && (bonuses['type'] == 'bonus')) {
this.bonus = '${user['bonus']}';
}
print('kifio ' + this.loyalty);
print('bonus ' + this.bonus);
}
}