Получение информации о пользователе, разные исправления
This commit is contained in:
@@ -9,12 +9,41 @@ import 'purchase_success.dart';
|
||||
|
||||
/// Экран проведения покупки.
|
||||
class PurchaseScreen extends StatefulWidget {
|
||||
@override State createState() => new PurchaseScreenState<PurchaseScreen>();
|
||||
|
||||
PurchaseScreen(this.response, this.card);
|
||||
|
||||
Map response;
|
||||
String card;
|
||||
|
||||
@override State createState() => new PurchaseScreenState<PurchaseScreen>(response, card);
|
||||
}
|
||||
|
||||
class PurchaseScreenState<T> extends BaseState<T> {
|
||||
class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
|
||||
PurchaseScreenState(Map user, String card) {
|
||||
this.user = user;
|
||||
this.card = card;
|
||||
getLoyality(user['loyalty_url']);
|
||||
}
|
||||
|
||||
Map user;
|
||||
String card;
|
||||
String integerPart = '', fractionalPart = '';
|
||||
String loyality = '';
|
||||
|
||||
@override Widget getScreenContent() {
|
||||
return new Container(height: 412.0,
|
||||
child: new ListView(reverse: true, children: <Widget>[
|
||||
new Column(children: <Widget>[
|
||||
getValueWithTitle('ФИО', user['first_name']),
|
||||
getValueWithTitle('Карта', card),
|
||||
getValueWithTitle('Вознаграждение', loyality),
|
||||
getHintLabel(),
|
||||
getDecoratedTextWidget(),
|
||||
buildButton(new EdgeInsets.only(top: 36.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildRaisedButton(context, 'ЗАВЕРШИТЬ ПОКУПКУ', () => _purchase(context))),
|
||||
buildButton(new EdgeInsets.only(top: 24.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildFlatButton(context, 'СКАНИРОВАТЬ', primaryColor))])
|
||||
].reversed.toList()));
|
||||
}
|
||||
|
||||
@override String getTitle() {
|
||||
return "Проведение покупки";
|
||||
@@ -25,24 +54,7 @@ class PurchaseScreenState<T> extends BaseState<T> {
|
||||
}
|
||||
|
||||
@overide getMenuButtons(BuildContext context) {
|
||||
return <Widget>[
|
||||
new getFaqButton(),
|
||||
new getLogoutButton()
|
||||
];
|
||||
}
|
||||
|
||||
@override Widget getScreenContent() {
|
||||
return new Container(height: 412.0,
|
||||
child: new ListView(reverse: true, children: <Widget>[
|
||||
new Column(children: <Widget>[
|
||||
getValueWithTitle('ФИО', 'Знаменитый Рокер Паук'),
|
||||
getValueWithTitle('Карта', 'B0399900702'),
|
||||
getValueWithTitle('Вознаграждение', '100%'),
|
||||
getHintLabel(),
|
||||
getDecoratedTextWidget(),
|
||||
buildButton(new EdgeInsets.only(top: 36.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildRaisedButton(context, 'ЗАВЕРШИТЬ ПОКУПКУ', () => _purchase(context))),
|
||||
buildButton(new EdgeInsets.only(top: 24.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildFlatButton(context, 'СКАНИРОВАТЬ', primaryColor))])
|
||||
].reversed.toList()));
|
||||
return <Widget>[getFaqButton(), getLogoutButton()];
|
||||
}
|
||||
|
||||
@override Color getTextFilledBackground() {
|
||||
@@ -71,6 +83,35 @@ class PurchaseScreenState<T> extends BaseState<T> {
|
||||
});
|
||||
}
|
||||
|
||||
getLoyality(String url) {
|
||||
|
||||
var headers = {
|
||||
'DM-Authorization': 'dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08',
|
||||
'Authorization': 'dmtoken ${token}'
|
||||
};
|
||||
|
||||
httpClient.get(url, headers: headers).then((response) {
|
||||
|
||||
print(response.body);
|
||||
|
||||
Map bonuses = JSON.decode(response.body);
|
||||
String type = bonuses['type'];
|
||||
|
||||
setState(() {
|
||||
if (type == 'amount') {
|
||||
this.loyality = user['discount'];
|
||||
} else {
|
||||
List bonusToAmount = bonuses['bonus_to_amount'];
|
||||
this.loyality = (bonusToAmount[1].toInt() / bonusToAmount[0].toInt() ).toString();
|
||||
}
|
||||
});
|
||||
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
_buildSum() {
|
||||
String temporaryInteger = integerPart;
|
||||
String temporaryFractional = fractionalPart;
|
||||
@@ -84,6 +125,7 @@ class PurchaseScreenState<T> extends BaseState<T> {
|
||||
|
||||
_purchase(BuildContext context) {
|
||||
String val = _buildSum();
|
||||
print(val);
|
||||
showDialog(context: context, child: new AlertDialog(
|
||||
title: new Text('Подтверждение'),
|
||||
content: new Text('Вы подтверждаете покупку на ${val} руб?'),
|
||||
@@ -97,7 +139,8 @@ class PurchaseScreenState<T> extends BaseState<T> {
|
||||
new FlatButton(
|
||||
child: new Text('Да'),
|
||||
onPressed: () {
|
||||
pushRoute(context, new PurchaseSuccessScreen(val));
|
||||
Navigator.of(context).pop();
|
||||
pushRoute(context, new PurchaseSuccessScreen(val, user['first_name']));
|
||||
},
|
||||
)
|
||||
]));
|
||||
|
||||
Reference in New Issue
Block a user