списание бонусов при покупке(часть)
This commit is contained in:
@@ -139,7 +139,8 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
||||
return new Container(margin: new EdgeInsets.only(left: verticalMargin, right: verticalMargin),
|
||||
padding: getInputFieldContainerPadding(),
|
||||
decoration: getInputFieldContainerDecoration(),
|
||||
child: getTextWidget());
|
||||
child: getTextWidget()
|
||||
);
|
||||
}
|
||||
|
||||
/// Возвращает поле ввода.
|
||||
@@ -203,4 +204,4 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
||||
Widget wrapButton(EdgeInsets margin, Widget widget) {
|
||||
return new Container(margin: margin, height: buttonHeight, child: new Row(children: <Widget>[new Expanded(child: widget)]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +144,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
||||
String userString = call.arguments[0];
|
||||
print(userString);
|
||||
String card = call.arguments[1];
|
||||
print('$userString, $card');
|
||||
var route = new MaterialPageRoute<Null>(
|
||||
builder: (BuildContext context) =>
|
||||
new PurchaseScreen(helper, app, userString, card));
|
||||
@@ -155,7 +156,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
||||
});
|
||||
|
||||
platform.invokeMethod('startScanner', {
|
||||
'token': await platform.invokeMethod('getAppToken'),
|
||||
'token': token,
|
||||
'url': await platform.invokeMethod('getEndpoint'),
|
||||
'appToken': await platform.invokeMethod('getAppToken'),
|
||||
'locale': Intl.defaultLocale,
|
||||
|
||||
@@ -40,6 +40,8 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"discount_sum" : MessageLookupByLibrary.simpleMessage("Dicount Sum"),
|
||||
"bonus_plus" : MessageLookupByLibrary.simpleMessage("Bonus points"),
|
||||
"bonus_minus" : MessageLookupByLibrary.simpleMessage("Bonus was charged"),
|
||||
"bonus_hint" : MessageLookupByLibrary.simpleMessage("Points to charge"),
|
||||
"bonus_explanation" : MessageLookupByLibrary.simpleMessage("If not set, points will be added"),
|
||||
"scan" : MessageLookupByLibrary.simpleMessage("Scan"),
|
||||
"sign_up" : MessageLookupByLibrary.simpleMessage("Sign Up"),
|
||||
"specify_din_store" : MessageLookupByLibrary.simpleMessage("Specify the store ID"),
|
||||
|
||||
@@ -40,6 +40,8 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"discount_sum" : MessageLookupByLibrary.simpleMessage("Сумма скидки"),
|
||||
"bonus_plus" : MessageLookupByLibrary.simpleMessage("Бонусов начислено"),
|
||||
"bonus_minus" : MessageLookupByLibrary.simpleMessage("Бонусов списано"),
|
||||
"bonus_hint" : MessageLookupByLibrary.simpleMessage("Сколько баллов списать?"),
|
||||
"bonus_explanation" : MessageLookupByLibrary.simpleMessage("Если не указано сколько баллов списать, баллы будут начислены"),
|
||||
"scan" : MessageLookupByLibrary.simpleMessage("Сканировать"),
|
||||
"sign_up" : MessageLookupByLibrary.simpleMessage("Зарегистрироваться"),
|
||||
"specify_din_store" : MessageLookupByLibrary.simpleMessage("Необходимо указать ID магазина"),
|
||||
|
||||
@@ -31,6 +31,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
/// (удаляет запрещенные символы до их отображаения).
|
||||
TextEditingController controller = new TextEditingController();
|
||||
|
||||
TextEditingController bonusController = new TextEditingController();
|
||||
|
||||
PurchaseScreenState(SqliteHelper helper, String app, String userString, String card) {
|
||||
this.user = JSON.decode(userString);
|
||||
this.card = card;
|
||||
@@ -62,13 +64,19 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
));
|
||||
widgets.add(getValueWithDescription(StringsLocalization.card(), card));
|
||||
|
||||
widgets.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
|
||||
|
||||
if (bonus.length > 0) {
|
||||
widgets.add(getValueWithDescription(StringsLocalization.bonus(), bonus));
|
||||
}
|
||||
|
||||
widgets.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
|
||||
widgets.add(getHintLabel());
|
||||
widgets.add(getInputField());
|
||||
|
||||
widgets.add(getInputField()); // Нельзя добавить еще одно поле таким же способом
|
||||
|
||||
widgets.add(getBonusInputField());
|
||||
|
||||
|
||||
widgets.add(wrapButton(getScreenMargins(36.0), getCompleteButton()));
|
||||
widgets.add(wrapButton(
|
||||
getScreenMargins(24.0),
|
||||
@@ -84,6 +92,47 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
]);
|
||||
}
|
||||
|
||||
getBonusInputField() {
|
||||
return new Column(
|
||||
children: <Widget>[
|
||||
new Container(
|
||||
margin: new EdgeInsets.only(
|
||||
left: verticalMargin,
|
||||
right: verticalMargin,
|
||||
top: verticalMargin
|
||||
),
|
||||
padding: getInputFieldContainerPadding(),
|
||||
decoration: getInputFieldContainerDecoration(),
|
||||
child: new TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: new InputDecoration.collapsed(
|
||||
hintText: StringsLocalization.bonusHint(),
|
||||
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
|
||||
controller: bonusController,
|
||||
onSubmitted: (String text) {
|
||||
setState(() {
|
||||
bonusController.text = text;
|
||||
});
|
||||
},
|
||||
textAlign: TextAlign.center,
|
||||
autofocus: true,
|
||||
)
|
||||
),
|
||||
new Container(
|
||||
margin: new EdgeInsets.only(
|
||||
top: 5.0
|
||||
),
|
||||
child: new Text(
|
||||
StringsLocalization.bonusExplanation(),
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: new TextStyle(color: greyTextColor, fontSize: 11.0),
|
||||
)
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
getScreenMargins(double top) {
|
||||
double side = 42.0;
|
||||
return new EdgeInsets.only(top: top, left: side, right: side);
|
||||
@@ -118,6 +167,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
|
||||
@override
|
||||
getTextWidget() {
|
||||
// ?? TODO переделать, т.к. позволяет иметь только одно поле ввода на странице
|
||||
return new TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: new InputDecoration.collapsed(
|
||||
@@ -195,7 +245,9 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
child: new AlertDialog(
|
||||
title: new Text(StringsLocalization.confirmation()),
|
||||
content:
|
||||
new Text(StringsLocalization.confirmPurchase(val, currency)),
|
||||
new Text(
|
||||
StringsLocalization.confirmPurchase(val, currency)
|
||||
),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text(StringsLocalization.no()),
|
||||
@@ -213,6 +265,24 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
apiErrorAlert(String errorText) {
|
||||
showDialog(
|
||||
context: context,
|
||||
child: new AlertDialog(
|
||||
//title: new Text(StringsLocalization.()),
|
||||
content: new Text(errorText),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text('Ok'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
purchase(String sumTotal) async {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
if (!purchaseInProgress) {
|
||||
@@ -229,17 +299,28 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
'sum_total': sumTotal
|
||||
};
|
||||
|
||||
if (bonusController.text.length > 0) {
|
||||
body['bonus_payment'] = bonusController.text;
|
||||
}
|
||||
|
||||
print(body['bonus_payment']);
|
||||
|
||||
var purchaseResponse;
|
||||
Map purchase;
|
||||
|
||||
try {
|
||||
purchaseResponse = await getPurchaseRequest(user['purchases_url'], body, token);
|
||||
print(purchaseResponse.body);
|
||||
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());
|
||||
}
|
||||
|
||||
Map purchase = JSON.decode(purchaseResponse.body);
|
||||
}
|
||||
|
||||
Navigator.of(context).pop();
|
||||
|
||||
|
||||
@@ -101,6 +101,8 @@ class StringsLocalization {
|
||||
static String completePurchase() => Intl.message('complite_purchase', name: 'complite_purchase', locale: Intl.defaultLocale);
|
||||
static String scan() => Intl.message('scan', name: 'scan', locale: Intl.defaultLocale);
|
||||
static String buyer() => Intl.message('buyer', name: 'buyer', locale: Intl.defaultLocale);
|
||||
static String bonusHint() => Intl.message('bonus_hint', name: 'bonus_hint', locale: Intl.defaultLocale);
|
||||
static String bonusExplanation() => Intl.message('bonus_explanation', name: 'bonus_explanation', locale: Intl.defaultLocale);
|
||||
static String discountRate() => Intl.message('discount_rate', name: 'discount_rate', locale: Intl.defaultLocale);
|
||||
static String discountSum() => Intl.message('discount_sum', name: 'discount_sum', locale: Intl.defaultLocale);
|
||||
static String bonusPlus() => Intl.message('bonus_plus', name: 'bonus_plus', locale: Intl.defaultLocale);
|
||||
|
||||
Reference in New Issue
Block a user