Локаль можно задать на этапе сборки

This commit is contained in:
Ivan Murashov
2017-09-06 14:01:12 +03:00
parent 3bd9eb4d91
commit 60090ea437
25 changed files with 226 additions and 385 deletions

View File

@@ -31,24 +31,24 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
PurchaseScreenState(String userString, String card) {
this.user = JSON.decode(userString);
this.card = card;
getLoyality(user['loyalty_url']);
getLoyalty(user['loyalty_url']);
}
bool purchaseInProgress = false;
Map user;
String card = '';
String loyality = '';
String loyalty = '';
@override Widget getScreenContent() {
return new Column(
children: <Widget>[new Expanded(child: new ListView(children: <Widget>[
getValueWithDescription(Strings.of(context).userName(), user['first_name'] == null ? '' : user['first_name']),
getValueWithDescription(Strings.of(context).card(), card),
getValueWithDescription(Strings.of(context).reward(), loyality),
getValueWithDescription(StringsLocalization.userName(), user['first_name'] == null ? '' : user['first_name']),
getValueWithDescription(StringsLocalization.card(), card),
getValueWithDescription(StringsLocalization.reward(), loyalty),
getHintLabel(),
getInputField(),
buildButton(getScreenMargins(36.0), getCompleteButton()),
buildButton(getScreenMargins(24.0), getScanButton(context, Strings.of(context).scan(), primaryColor))
wrapButton(getScreenMargins(36.0), getCompleteButton()),
wrapButton(getScreenMargins(24.0), getScanButton(context, StringsLocalization.scan(), primaryColor))
]))]);
}
@@ -58,8 +58,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
}
getCompleteButton() {
String title = Strings.of(context).completePurchase();
return buildRaisedButton(context, title, () => onPurchaseClick(context));
return buildRaisedButton(StringsLocalization.completePurchase(), () => onPurchaseClick());
}
Widget getScanButton(BuildContext context, String title, Color textColor) {
@@ -76,21 +75,17 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
}
@override String getTitle() {
return Strings.of(context).carryingPurchase();
return StringsLocalization.carryingPurchase();
}
@override getHint() {
return Strings.of(context).sum();
return StringsLocalization.sum();
}
@override getMenuButtons(BuildContext context) {
@override getMenuButtons() {
return <Widget>[getFaqButton(), getLogoutButton()];
}
@override Color getTextFilledBackground() {
return Colors.white;
}
@override getTextWidget() {
return new TextField(
keyboardType: TextInputType.number,
@@ -109,10 +104,12 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
);
}
getLoyality(String url) async {
getLoyalty(String url) async {
if (await platform.invokeMethod('isOnline')) {
String token = await platform.invokeMethod('getToken');
var headers = {
'DM-Authorization': 'dmapptoken $appToken',
'Authorization': 'dmtoken ${token}'
@@ -126,11 +123,11 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
String type = bonuses['type'];
setState(() {
if (type == 'amount') {
this.loyality = '${user['discount']}%';
this.loyalty = '${user['discount']}%';
} else {
List amountToBonus = bonuses['amount_to_bonus'];
double loyalityVal = (double.parse(amountToBonus[1]) / amountToBonus[0]) * 100;
this.loyality = '${loyalityVal.toStringAsFixed(0)}%';
this.loyalty = '${loyalityVal.toStringAsFixed(0)}%';
}
});
}).catchError((error) {
@@ -175,20 +172,20 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
return sumTotal.toStringAsFixed(2);
}
onPurchaseClick(BuildContext context) {
onPurchaseClick() {
String val = _parseSum(controller.text);
showDialog(context: context, child: new AlertDialog(
title: new Text(Strings.of(context).confirmation()),
content: new Text(getContentMessage(val)),
title: new Text(StringsLocalization.confirmation()),
content: new Text(StringsLocalization.confirmPurchase(val)),
actions: <Widget>[
new FlatButton(
child: new Text(Strings.of(context).no()),
child: new Text(StringsLocalization.no()),
onPressed: () {
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text(Strings.of(context).yes()),
child: new Text(StringsLocalization.yes()),
onPressed: () {
purchase(val);
},
@@ -196,14 +193,12 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
]));
}
getContentMessage(String val) {
return Strings.of(context).confirmPurchase();
}
purchase(String sumTotal) async {
if (await platform.invokeMethod('isOnline')) {
if (!purchaseInProgress) {
purchaseInProgress = true;
String token = await platform.invokeMethod('getToken');
platform.invokeMethod('getDocID').then((result) {
String url = user['purchases_url'];