#12267 change scan flow
This commit is contained in:
@@ -38,6 +38,7 @@ public class MainActivity extends FlutterActivity {
|
|||||||
|
|
||||||
private MethodChannel mChannel;
|
private MethodChannel mChannel;
|
||||||
private Map mScannerArgs;
|
private Map mScannerArgs;
|
||||||
|
private Result scannerResult;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -59,6 +60,7 @@ public class MainActivity extends FlutterActivity {
|
|||||||
result.success(BuildConfig.currency);
|
result.success(BuildConfig.currency);
|
||||||
break;
|
break;
|
||||||
case "startScanner":
|
case "startScanner":
|
||||||
|
scannerResult = result;
|
||||||
startScannerActivity(call);
|
startScannerActivity(call);
|
||||||
break;
|
break;
|
||||||
case "isOnline":
|
case "isOnline":
|
||||||
@@ -169,7 +171,7 @@ public class MainActivity extends FlutterActivity {
|
|||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == START_SCANNER_REQUEST_CODE) {
|
if (requestCode == START_SCANNER_REQUEST_CODE) {
|
||||||
if (resultCode == RESULT_CANCELED) {
|
if (resultCode == RESULT_CANCELED) {
|
||||||
finish();
|
scannerResult.error("Scanning is cancelled", null, null);
|
||||||
} else if (resultCode == RESULT_OK) {
|
} else if (resultCode == RESULT_OK) {
|
||||||
if (data != null && data.getExtras() != null) {
|
if (data != null && data.getExtras() != null) {
|
||||||
String user = data.getExtras().getString("user", null);
|
String user = data.getExtras().getString("user", null);
|
||||||
@@ -178,7 +180,9 @@ public class MainActivity extends FlutterActivity {
|
|||||||
ArrayList<String> args = new ArrayList<>(2);
|
ArrayList<String> args = new ArrayList<>(2);
|
||||||
args.add(user);
|
args.add(user);
|
||||||
args.add(card);
|
args.add(card);
|
||||||
mChannel.invokeMethod("purchase", args);
|
if(scannerResult != null) {
|
||||||
|
scannerResult.success(args);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
String menuItem = data.getExtras().getString("item", null);
|
String menuItem = data.getExtras().getString("item", null);
|
||||||
if (menuItem != null) {
|
if (menuItem != null) {
|
||||||
|
|||||||
@@ -153,4 +153,7 @@ Set on switch on Camera
|
|||||||
Go back to %s.
|
Go back to %s.
|
||||||
</string>
|
</string>
|
||||||
<string name="open_settings">Open settings</string>
|
<string name="open_settings">Open settings</string>
|
||||||
|
<string name="cancel">Cancel</string>
|
||||||
|
<string name="purchase_cancellation">Are you sure you want to cancel this purchase?</string>
|
||||||
|
<string name="purchase_details">Total amount: %s %s, with discount of %s %s (%s%%)</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -149,4 +149,5 @@ Establecer en el interruptor de la cámara
|
|||||||
Vuelve a %s
|
Vuelve a %s
|
||||||
</string>
|
</string>
|
||||||
<string name="open_settings">Abre las configuraciones</string>
|
<string name="open_settings">Abre las configuraciones</string>
|
||||||
|
<string name="cancel">Cancelar</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -152,4 +152,6 @@
|
|||||||
Вернитесь к приложению %s.
|
Вернитесь к приложению %s.
|
||||||
</string>
|
</string>
|
||||||
<string name="open_settings">Открыть настройки</string>
|
<string name="open_settings">Открыть настройки</string>
|
||||||
|
<string name="cancel">Отмена</string>
|
||||||
|
<string name="purchase_cancellation">Вы уверены что хотите отменить покупку?</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -154,4 +154,5 @@
|
|||||||
Поверніться до додатка %s.
|
Поверніться до додатка %s.
|
||||||
</string>
|
</string>
|
||||||
<string name="open_settings">Відкрити параметри</string>
|
<string name="open_settings">Відкрити параметри</string>
|
||||||
|
<string name="cancel">Скасувати</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ import ZXingObjC
|
|||||||
} else {
|
} else {
|
||||||
print("Result is not nil (ios code)");
|
print("Result is not nil (ios code)");
|
||||||
self.dismiss(animated: true) {
|
self.dismiss(animated: true) {
|
||||||
self.platformChannel?.invokeMethod("purchase", arguments: [result, str])
|
self.platformChannel?.invokeMethod("scanSuccess", arguments: [result!, str])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import 'package:checker/screens/faq.dart';
|
|||||||
import 'package:checker/strings.dart';
|
import 'package:checker/strings.dart';
|
||||||
import 'package:checker/db.dart';
|
import 'package:checker/db.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:meta/meta.dart';
|
|
||||||
|
|
||||||
abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:checker/base/base_screen.dart';
|
import 'package:checker/base/base_screen.dart';
|
||||||
import 'package:checker/base/base_state.dart';
|
import 'package:checker/base/base_state.dart';
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:checker/base/base_screen.dart';
|
import 'package:checker/base/base_screen.dart';
|
||||||
import 'package:checker/db.dart';
|
import 'package:checker/db.dart';
|
||||||
|
import 'package:checker/screens/purchase_sum.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
@@ -14,13 +15,16 @@ import 'package:checker/network.dart';
|
|||||||
import 'package:checker/base/base_state.dart';
|
import 'package:checker/base/base_state.dart';
|
||||||
import 'package:checker/screens/purchase_success.dart';
|
import 'package:checker/screens/purchase_success.dart';
|
||||||
|
|
||||||
|
typedef PurchaseResponseCallback = void Function(Map, String, String);
|
||||||
|
|
||||||
/// Экран проведения покупки.
|
/// Экран проведения покупки.
|
||||||
class PurchaseScreen extends BaseScreen {
|
class PurchaseScreen extends BaseScreen {
|
||||||
|
|
||||||
PurchaseScreen(helper, app, this.user, this.card) : super(helper, app);
|
PurchaseScreen(helper, app, this.user, this.card, this.sum) : super(helper, app);
|
||||||
|
|
||||||
final String user;
|
final String user;
|
||||||
final String card;
|
final String card;
|
||||||
|
final String sum;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State createState() => new PurchaseScreenState<PurchaseScreen>(helper, app, user, card);
|
State createState() => new PurchaseScreenState<PurchaseScreen>(helper, app, user, card);
|
||||||
@@ -30,7 +34,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
/// Объект, помогающий вручную изменять введенный пользователем текст.
|
/// Объект, помогающий вручную изменять введенный пользователем текст.
|
||||||
/// Используется для форматирования введенных пользователем данных
|
/// Используется для форматирования введенных пользователем данных
|
||||||
/// (удаляет запрещенные символы до их отображаения).
|
/// (удаляет запрещенные символы до их отображаения).
|
||||||
TextEditingController controller = new TextEditingController();
|
TextEditingController controller;
|
||||||
|
|
||||||
TextEditingController bonusController = new TextEditingController();
|
TextEditingController bonusController = new TextEditingController();
|
||||||
|
|
||||||
@@ -43,6 +47,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
controller = new TextEditingController(text: widget.sum ?? "");
|
||||||
loading = true;
|
loading = true;
|
||||||
requestAsyncData(user);
|
requestAsyncData(user);
|
||||||
buildFocusNode();
|
buildFocusNode();
|
||||||
@@ -116,9 +121,9 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
|
|
||||||
widgetList.add(wrapButton(
|
widgetList.add(wrapButton(
|
||||||
getScreenMargins(24.0),
|
getScreenMargins(24.0),
|
||||||
getScanButton(
|
getCancelScanButton(
|
||||||
context,
|
context,
|
||||||
StringsLocalization.scan(),
|
StringsLocalization.cancel(),
|
||||||
Resources.getPrimaryColor(app)
|
Resources.getPrimaryColor(app)
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
@@ -185,12 +190,12 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
StringsLocalization.completePurchase(), () => onPurchaseClick());
|
StringsLocalization.completePurchase(), () => onPurchaseClick());
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget getScanButton(BuildContext context, String title, Color textColor) {
|
Widget getCancelScanButton(BuildContext context, String title, Color textColor) {
|
||||||
return new Container(
|
return new Container(
|
||||||
height: buttonHeight,
|
height: buttonHeight,
|
||||||
child: new FlatButton(
|
child: new FlatButton(
|
||||||
child: new Text(title, style: new TextStyle(color: textColor)),
|
child: new Text(title, style: new TextStyle(color: textColor)),
|
||||||
onPressed: () => restartScanner()),
|
onPressed: () => restartFlow()),
|
||||||
decoration: new BoxDecoration(
|
decoration: new BoxDecoration(
|
||||||
border: new Border.all(
|
border: new Border.all(
|
||||||
color: Resources.getButtonColor(app), width: 1.0),
|
color: Resources.getButtonColor(app), width: 1.0),
|
||||||
@@ -249,8 +254,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
loading = false;
|
loading = false;
|
||||||
this.coupons = coupons['results'];
|
this.coupons = coupons['results'];
|
||||||
this.loyalityType = loyality['type'];
|
this.loyalityType = loyality['type'];
|
||||||
setBonuses(loyality, showBonus);
|
|
||||||
});
|
});
|
||||||
|
setBonuses(loyality, showBonus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,16 +298,26 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onPurchaseClick() {
|
onPurchaseClick() {
|
||||||
|
String val = _parseSum(controller.text);
|
||||||
|
purchase(val, false, _showPrecalculatedValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showPrecalculatedValues(Map response, String sumTotal, String token) {
|
||||||
String val = _parseSum(controller.text);
|
String val = _parseSum(controller.text);
|
||||||
helper.getCurrency().then((currency) {
|
helper.getCurrency().then((currency) {
|
||||||
print(currency.toString());
|
print(currency.toString());
|
||||||
|
final String totalAmount = response['sum_total'];
|
||||||
|
final String totalDiscount = response['sum_discount'];
|
||||||
|
final String discount = (response['discount'] as int).toString();
|
||||||
|
print(response);
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => new AlertDialog(
|
builder: (_) =>
|
||||||
|
new AlertDialog(
|
||||||
title: new Text(StringsLocalization.confirmation()),
|
title: new Text(StringsLocalization.confirmation()),
|
||||||
content:
|
content: Text(
|
||||||
new Text(
|
StringsLocalization.purchaseDetails(totalAmount,
|
||||||
StringsLocalization.confirmPurchase(val, currency)
|
totalDiscount, discount, currency)
|
||||||
),
|
),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
new FlatButton(
|
new FlatButton(
|
||||||
@@ -315,13 +330,42 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
child: new Text(StringsLocalization.yes()),
|
child: new Text(StringsLocalization.yes()),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
purchase(val);
|
purchase(val, true, _paymentConfirmed);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _paymentConfirmed(Map purchase, String sumTotal, String token) async {
|
||||||
|
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);
|
||||||
|
|
||||||
|
new Future.delayed(const Duration(milliseconds: 200), () {
|
||||||
|
print('show purchase success!');
|
||||||
|
var route = new MaterialPageRoute<String>(builder: (BuildContext context) => new PurchaseSuccessScreen(
|
||||||
|
sumTotal,
|
||||||
|
user['first_name'] == null ? '' : user['first_name'],
|
||||||
|
helper,
|
||||||
|
app,
|
||||||
|
purchase,
|
||||||
|
coupons['results']
|
||||||
|
), fullscreenDialog: true);
|
||||||
|
Navigator.of(context).push(route).then((token) {
|
||||||
|
Navigator.of(context).pop(token);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
apiErrorAlert(String errorText) {
|
apiErrorAlert(String errorText) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -339,13 +383,13 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
purchase(String sumTotal) async {
|
purchase(String sumTotal, bool commit, PurchaseResponseCallback callback) async {
|
||||||
setState(() {
|
setState(() {
|
||||||
loading = true;
|
loading = true;
|
||||||
});
|
});
|
||||||
if (await platform.invokeMethod('isOnline')) {
|
if (await platform.invokeMethod('isOnline')) {
|
||||||
if (!purchaseInProgress) {
|
if (!purchaseInProgress) {
|
||||||
purchaseInProgress = true;
|
purchaseInProgress = commit;
|
||||||
|
|
||||||
String token = await helper.getToken();
|
String token = await helper.getToken();
|
||||||
var result = await helper.getMerchantID();
|
var result = await helper.getMerchantID();
|
||||||
@@ -361,10 +405,13 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
var body = {
|
var body = {
|
||||||
'doc_id': result,
|
'doc_id': result,
|
||||||
'curr_iso_code': currency.toString(),
|
'curr_iso_code': currency.toString(),
|
||||||
'commit': 'true',
|
|
||||||
'sum_total': sumTotal,
|
'sum_total': sumTotal,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(commit) {
|
||||||
|
body['commit'] = 'true';
|
||||||
|
}
|
||||||
|
|
||||||
if (bonusController.text.length > 0) {
|
if (bonusController.text.length > 0) {
|
||||||
body['bonus_payment'] = bonusController.text;
|
body['bonus_payment'] = bonusController.text;
|
||||||
}
|
}
|
||||||
@@ -392,32 +439,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
purchaseInProgress = false;
|
purchaseInProgress = false;
|
||||||
apiErrorAlert(errors[0]);
|
apiErrorAlert(errors[0]);
|
||||||
} else {
|
} else {
|
||||||
var couponsResponse;
|
callback(purchase, sumTotal, token);
|
||||||
|
|
||||||
try {
|
|
||||||
couponsResponse = await getCouponsRequest(purchase['coupons_url'], token);
|
|
||||||
print(couponsResponse.body);
|
|
||||||
} catch(error) {
|
|
||||||
purchaseInProgress = false;
|
|
||||||
print(error.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
Map coupons = json.decode(couponsResponse.body);
|
|
||||||
|
|
||||||
new Future.delayed(const Duration(milliseconds: 200), () {
|
|
||||||
print('show purchase success!');
|
|
||||||
var route = new MaterialPageRoute<String>(builder: (BuildContext context) => new PurchaseSuccessScreen(
|
|
||||||
sumTotal,
|
|
||||||
user['first_name'] == null ? '' : user['first_name'],
|
|
||||||
helper,
|
|
||||||
app,
|
|
||||||
purchase,
|
|
||||||
coupons['results']
|
|
||||||
), fullscreenDialog: true);
|
|
||||||
Navigator.of(context).push(route).then((token) {
|
|
||||||
Navigator.of(context).pop(token);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -426,24 +448,47 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
void setBonuses(Map bonuses, bool showBonus) {
|
void setBonuses(Map bonuses, bool showBonus) {
|
||||||
print('loyalityType ' + this.loyalityType);
|
print('loyalityType ' + this.loyalityType);
|
||||||
if (bonuses['type'] == 'amount') {
|
if (bonuses['type'] == 'amount') {
|
||||||
this.loyalty = '${user['discount']}%';
|
setState(() => this.loyalty = '${user['discount']}%');
|
||||||
} else {
|
} else {
|
||||||
double loyaltyVal = (double.parse(bonuses['amount_to_bonus'][1]) /
|
double loyaltyVal = (double.parse(bonuses['amount_to_bonus'][1]) /
|
||||||
bonuses['amount_to_bonus'][0]) * 100;
|
bonuses['amount_to_bonus'][0]) * 100;
|
||||||
this.loyalty = '${loyaltyVal.toStringAsFixed(0)}%';
|
setState(() => this.loyalty = '${loyaltyVal.toStringAsFixed(0)}%');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showBonus && (this.loyalityType == 'bonus')) {
|
if (showBonus && (this.loyalityType == 'bonus')) {
|
||||||
this.bonus = '${user['bonus']}';
|
setState(() => this.bonus = '${user['bonus']}');
|
||||||
}
|
}
|
||||||
print('loyalty ' + this.loyalty);
|
print('loyalty ' + this.loyalty);
|
||||||
print('bonus ' + this.bonus);
|
print('bonus ' + this.bonus);
|
||||||
}
|
}
|
||||||
|
|
||||||
restartScanner() {
|
restartFlow() {
|
||||||
helper.getToken().then((token) {
|
showDialog(
|
||||||
Navigator.of(context).pop(token);
|
context: context,
|
||||||
});
|
builder: (context) => AlertDialog(
|
||||||
|
content: Text(StringsLocalization.cancelDialog()),
|
||||||
|
actions: <Widget>[
|
||||||
|
new FlatButton(
|
||||||
|
child: new Text(StringsLocalization.no()),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
new FlatButton(
|
||||||
|
child: new Text(StringsLocalization.yes()),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
helper.getToken().then((token) {
|
||||||
|
Navigator.pushAndRemoveUntil(context,
|
||||||
|
MaterialPageRoute(builder: (context) =>
|
||||||
|
PurchaseSumScreen(widget.helper, widget.app, token)),
|
||||||
|
(route) => false);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
FocusNode bonusFocusNode = new FocusNode();
|
FocusNode bonusFocusNode = new FocusNode();
|
||||||
@@ -456,25 +501,14 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
|
|
||||||
sumFocusNode.addListener(() {
|
sumFocusNode.addListener(() {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
||||||
if (sumFocusNode.hasFocus && bonusFocusNode.hasFocus) {
|
|
||||||
bonusFocusNode.unfocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sumFocusNode.hasFocus) {
|
if (sumFocusNode.hasFocus) {
|
||||||
scrollController.animateTo(pos, duration: new Duration(seconds: 1), curve: Curves.ease);
|
sumFocusNode.unfocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
bonusFocusNode.addListener(() {
|
bonusFocusNode.addListener(() {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
||||||
if (bonusFocusNode.hasFocus && sumFocusNode.hasFocus) {
|
|
||||||
sumFocusNode.unfocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bonusFocusNode.hasFocus) {
|
if (bonusFocusNode.hasFocus) {
|
||||||
scrollController.animateTo(pos, duration: new Duration(seconds: 1), curve: Curves.ease);
|
scrollController.animateTo(pos, duration: new Duration(seconds: 1), curve: Curves.ease);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:checker/base/base_state.dart';
|
|||||||
import 'package:checker/common.dart';
|
import 'package:checker/common.dart';
|
||||||
import 'package:checker/consts.dart';
|
import 'package:checker/consts.dart';
|
||||||
import 'package:checker/db.dart';
|
import 'package:checker/db.dart';
|
||||||
|
import 'package:checker/screens/purchase_sum.dart';
|
||||||
import 'package:checker/strings.dart';
|
import 'package:checker/strings.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@@ -135,7 +136,11 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
|
|||||||
|
|
||||||
getScanButton() {
|
getScanButton() {
|
||||||
String title = StringsLocalization.scan();
|
String title = StringsLocalization.scan();
|
||||||
return buildRaisedButton(title, () => Navigator.of(context).pop(token));
|
return buildRaisedButton(title,
|
||||||
|
() => Navigator.pushAndRemoveUntil(context,
|
||||||
|
MaterialPageRoute(builder: (context) =>
|
||||||
|
PurchaseSumScreen(widget.helper, widget.app, token)),
|
||||||
|
(route) => false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
202
lib/screens/purchase_sum.dart
Normal file
202
lib/screens/purchase_sum.dart
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:checker/base/base_screen.dart';
|
||||||
|
import 'package:checker/db.dart';
|
||||||
|
import 'package:checker/screens/purchase.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
import 'dart:core';
|
||||||
|
|
||||||
|
import 'package:checker/resources.dart';
|
||||||
|
import 'package:checker/strings.dart';
|
||||||
|
import 'package:checker/common.dart';
|
||||||
|
import 'package:checker/consts.dart';
|
||||||
|
import 'package:checker/base/base_state.dart';
|
||||||
|
import 'package:checker/network.dart';
|
||||||
|
|
||||||
|
/// Экран ввода суммы покупки
|
||||||
|
class PurchaseSumScreen extends BaseScreen {
|
||||||
|
PurchaseSumScreen(helper, app, this.token) : super(helper, app);
|
||||||
|
|
||||||
|
final String token;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State createState() =>
|
||||||
|
new PurchaseSumScreenState<PurchaseSumScreen>(helper, app);
|
||||||
|
}
|
||||||
|
|
||||||
|
class PurchaseSumScreenState<T> extends BaseState<PurchaseSumScreen> {
|
||||||
|
TextEditingController _sumController = new TextEditingController();
|
||||||
|
|
||||||
|
bool isAutomaticallyImplyLeading() => false;
|
||||||
|
|
||||||
|
PurchaseSumScreenState(SqliteHelper helper, String app) : super(helper, app);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_subscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext ctx) {
|
||||||
|
return getMainWidget();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget getScreenContent() => Column(
|
||||||
|
children: <Widget>[
|
||||||
|
getHintLabel(),
|
||||||
|
getInputField(),
|
||||||
|
wrapButton(
|
||||||
|
_getScreenMargins(24.0),
|
||||||
|
getScanButton(context, StringsLocalization.scan(),
|
||||||
|
Resources.getPrimaryColor(app)))
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
EdgeInsets _getScreenMargins(double top) {
|
||||||
|
double side = 42.0;
|
||||||
|
return new EdgeInsets.only(top: top, left: side, right: side);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget getScanButton(BuildContext context, String title, Color textColor) {
|
||||||
|
return new Container(
|
||||||
|
height: buttonHeight,
|
||||||
|
child: new FlatButton(
|
||||||
|
child: new Text(title, style: new TextStyle(color: textColor)),
|
||||||
|
onPressed: () => _startScanner()),
|
||||||
|
decoration: new BoxDecoration(
|
||||||
|
border: new Border.all(
|
||||||
|
color: Resources.getButtonColor(app), width: 1.0),
|
||||||
|
borderRadius: new BorderRadius.all(new Radius.circular(4.0))));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _startScanner() {
|
||||||
|
platform.invokeMethod('getEndpoint').then((url) {
|
||||||
|
platform.invokeMethod('getAppToken').then((appToken) {
|
||||||
|
Map<String, String> args = StringsLocalization.strings;
|
||||||
|
args['token'] = widget.token;
|
||||||
|
args['url'] = url;
|
||||||
|
args['appToken'] = appToken;
|
||||||
|
args['localeCode'] = StringsLocalization.localeCode;
|
||||||
|
args['color'] = Resources.getPrimaryColor(app).value.toString();
|
||||||
|
platform.invokeMethod('startScanner', args).then((result) {
|
||||||
|
_processResult(result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String getTitle() {
|
||||||
|
return StringsLocalization.sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
getHintString() {
|
||||||
|
return StringsLocalization.sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
getTextWidget() {
|
||||||
|
return new TextField(
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
decoration: new InputDecoration.collapsed(
|
||||||
|
hintText: getHintString(),
|
||||||
|
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
|
||||||
|
controller: _sumController,
|
||||||
|
onSubmitted: (String text) {
|
||||||
|
setState(() {
|
||||||
|
_sumController.text = _parseSum(text);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
textAlign: TextAlign.center);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _cleanupNumber(String text) {
|
||||||
|
String tmp = text
|
||||||
|
.replaceAll(' ', '')
|
||||||
|
.replaceAll('-', '')
|
||||||
|
.replaceAll(',', '.')
|
||||||
|
.replaceAll('..', '.');
|
||||||
|
|
||||||
|
while (tmp.indexOf('..') != -1) {
|
||||||
|
tmp = tmp.replaceAll('..', '.');
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
String _parseSum(String input) {
|
||||||
|
num sumTotal = 0.0;
|
||||||
|
String text = _cleanupNumber(input);
|
||||||
|
|
||||||
|
try {
|
||||||
|
sumTotal = num.parse(text);
|
||||||
|
} catch (exception) {
|
||||||
|
print(exception);
|
||||||
|
try {
|
||||||
|
int idx = text.indexOf('.');
|
||||||
|
String integerPart = text.substring(0, idx);
|
||||||
|
String fractionalPart = text.substring(idx + 1, text.length);
|
||||||
|
if (fractionalPart.length > 2) {
|
||||||
|
fractionalPart = fractionalPart.substring(0, 2);
|
||||||
|
}
|
||||||
|
return '$integerPart.$fractionalPart';
|
||||||
|
} catch (exception) {
|
||||||
|
print(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print(sumTotal.toStringAsFixed(2));
|
||||||
|
return sumTotal.toStringAsFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _processResult(result) {
|
||||||
|
if (result is List) {
|
||||||
|
final String user = result[0] as String;
|
||||||
|
final String card = result[1] as String;
|
||||||
|
Navigator.of(context).push(new MaterialPageRoute(builder: (context) {
|
||||||
|
String sum = _parseSum(_sumController.text);
|
||||||
|
_sumController.text = "";
|
||||||
|
return PurchaseScreen(helper, app, user, card, sum);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _subscribe() async {
|
||||||
|
platform.setMethodCallHandler((MethodCall call) async {
|
||||||
|
if (call.method == 'findUser') {
|
||||||
|
try {
|
||||||
|
Response userResponse;
|
||||||
|
|
||||||
|
switch (call.arguments[1]) {
|
||||||
|
case 'card':
|
||||||
|
userResponse = await getUserByCard(call.arguments[0], widget.token);
|
||||||
|
break;
|
||||||
|
case 'phone':
|
||||||
|
userResponse = await getUserByPhone(call.arguments[0], widget.token);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userResponse != null) {
|
||||||
|
print('I have user in method handler!');
|
||||||
|
List<dynamic> users = json.decode(userResponse.body);
|
||||||
|
if (users.length > 0) {
|
||||||
|
return json.encode(users[0]);
|
||||||
|
} else {
|
||||||
|
throw new FlutterError("Users not found");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new FlutterError("Users not found");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
print(error.toString());
|
||||||
|
throw new FlutterError("Users not found");
|
||||||
|
}
|
||||||
|
} else if (call.method == 'scanSuccess') {
|
||||||
|
_processResult(call.arguments);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import 'package:checker/resources.dart';
|
|||||||
import 'package:checker/screens/faq.dart';
|
import 'package:checker/screens/faq.dart';
|
||||||
import 'package:checker/screens/finish_registration.dart';
|
import 'package:checker/screens/finish_registration.dart';
|
||||||
import 'package:checker/screens/purchase.dart';
|
import 'package:checker/screens/purchase.dart';
|
||||||
|
import 'package:checker/screens/purchase_sum.dart';
|
||||||
import 'package:checker/screens/registration.dart';
|
import 'package:checker/screens/registration.dart';
|
||||||
import 'package:checker/screens/settings.dart';
|
import 'package:checker/screens/settings.dart';
|
||||||
import 'package:checker/strings.dart';
|
import 'package:checker/strings.dart';
|
||||||
@@ -241,23 +242,13 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
|||||||
: json.encode(call.arguments[0]);
|
: json.encode(call.arguments[0]);
|
||||||
print(userString);
|
print(userString);
|
||||||
String card = call.arguments[1];
|
String card = call.arguments[1];
|
||||||
showNextScreen(new PurchaseScreen(helper, app, userString, card));
|
showNextScreen(new PurchaseScreen(helper, app, userString, card, null));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
platform.invokeMethod('getEndpoint').then((url) {
|
Navigator.of(context).pushReplacement(
|
||||||
platform.invokeMethod('getAppToken').then((appToken) {
|
MaterialPageRoute(builder: (context) =>
|
||||||
Map<String, String> args = StringsLocalization.strings;
|
PurchaseSumScreen(helper, app, token))
|
||||||
args['token'] = token;
|
);
|
||||||
args['url'] = url;
|
|
||||||
args['appToken'] = appToken;
|
|
||||||
args['localeCode'] = StringsLocalization.localeCode;
|
|
||||||
args['color'] = Resources
|
|
||||||
.getPrimaryColor(app)
|
|
||||||
.value
|
|
||||||
.toString();
|
|
||||||
platform.invokeMethod('startScanner', args);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,17 +111,25 @@ class StringsLocalization {
|
|||||||
return [nominative, singular, plural];
|
return [nominative, singular, plural];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static _normalizeDouble(String val) => val.substring(0, val.length - 3);
|
||||||
|
|
||||||
static String confirmPurchase(String val, int code) {
|
static String confirmPurchase(String val, int code) {
|
||||||
String trimmedVal = val.substring(0, val.length - 3);
|
String trimmedVal = _normalizeDouble(val);
|
||||||
return sprintf(strings['confirm_purchase'], [val, declineCurrency(int.parse(trimmedVal), code)]);
|
return sprintf(strings['confirm_purchase'], [val, declineCurrency(int.parse(trimmedVal), code)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String purchaseCompleted(String val, int code) {
|
static String purchaseCompleted(String val, int code) {
|
||||||
String trimmedVal = val.substring(0, val.length - 3);
|
String trimmedVal = _normalizeDouble(val);
|
||||||
return sprintf(strings['purchase_complite'], [val, declineCurrency(int.parse(trimmedVal), code)]);
|
return sprintf(strings['purchase_complite'], [val, declineCurrency(int.parse(trimmedVal), code)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String purchaseDetails(String total, String discountTotal, String discount, int code) {
|
||||||
|
final String normTotal = _normalizeDouble(total);
|
||||||
|
final String normDiscountTotal = _normalizeDouble(discountTotal);
|
||||||
|
return sprintf(strings['purchase_details'], [total, declineCurrency(int.parse(normTotal), code),
|
||||||
|
discountTotal, declineCurrency(int.parse(normDiscountTotal), code), discount]);
|
||||||
|
}
|
||||||
|
|
||||||
static String registration() => strings['registration'];
|
static String registration() => strings['registration'];
|
||||||
static String usage() => strings['usage'];
|
static String usage() => strings['usage'];
|
||||||
static String support() => strings['support'];
|
static String support() => strings['support'];
|
||||||
@@ -214,4 +222,6 @@ class StringsLocalization {
|
|||||||
static String joysMinus() => strings['joys_minus'];
|
static String joysMinus() => strings['joys_minus'];
|
||||||
static String joysHint() => strings['joys_hint'];
|
static String joysHint() => strings['joys_hint'];
|
||||||
static String phone() => strings['phone'];
|
static String phone() => strings['phone'];
|
||||||
|
static String cancel() => strings['cancel'];
|
||||||
|
static String cancelDialog() => strings['purchase_cancellation'];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user