Need fix error on purchase success showung.

This commit is contained in:
Ivan Murashov
2018-03-11 18:12:10 +03:00
parent 0c5645c059
commit 3bc43724c6
7 changed files with 47 additions and 56 deletions

View File

@@ -98,7 +98,12 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
void onOptionsItemClick(int index) {
switch (index) {
case 0: {
pushRoute(context, new SettingsScreen(helper, app, false));
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<String>(builder: (BuildContext context) => new SettingsScreen(helper, app, false), fullscreenDialog: true);
Navigator.of(context).push(route).then((token) {
Navigator.of(context).pop(token);
});
});
break;
}
case 1: {

View File

@@ -404,7 +404,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
new Future.delayed(const Duration(milliseconds: 200), () {
print('show purchase success!');
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => new PurchaseSuccessScreen(
var route = new MaterialPageRoute<String>(builder: (BuildContext context) => new PurchaseSuccessScreen(
sumTotal,
user['first_name'] == null ? '' : user['first_name'],
helper,
@@ -412,8 +412,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
purchase,
coupons['results']
), fullscreenDialog: true);
Navigator.of(context).push(route).then((_) {
Navigator.of(context).pop();
Navigator.of(context).push(route).then((token) {
Navigator.of(context).pop(token);
});
});
}

View File

@@ -122,9 +122,10 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
return new EdgeInsets.only(bottom: bottom, left: side, right: side);
}
getScanButton() {
getScanButton() async {
String title = StringsLocalization.scan();
return buildRaisedButton(title, () => Navigator.of(context).pop());
String token = await helper.getToken();
return buildRaisedButton(title, () => Navigator.of(context).pop(token));
}

View File

@@ -160,38 +160,14 @@ class SettingsState extends BaseState<SettingsScreen> {
}
// В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения.
logout(BuildContext context, SqliteHelper helper) async {
String token = await helper.getToken();
VoidCallback positiveCallback = () {
if (token != null) {
getDeleteTokenRequest(token).then((response) {
helper.clear().then((result) {
while (Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => new SplashScreen(helper, app));
new Future.delayed(const Duration(milliseconds: 200), () {
Navigator.of(context).pushReplacement(route);
});
});
}).catchError((error) {
print(error.toString());
});
} else {
while (Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
}
};
logout(BuildContext context, SqliteHelper helper) {
showYesNoDialog(context, StringsLocalization.confirmation(),
StringsLocalization.askChangeStore(), positiveCallback);
StringsLocalization.askChangeStore());
}
// Запуск диалога с двумя кнопками
showYesNoDialog(BuildContext context, String title, String content,
VoidCallback positiveCallback) {
showDialog(
showYesNoDialog(BuildContext context, String title, String content) {
showDialog<bool>(
context: context,
child: new AlertDialog(
title: new Text(title),
@@ -200,12 +176,27 @@ class SettingsState extends BaseState<SettingsScreen> {
new FlatButton(
child: new Text(StringsLocalization.no()),
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context).pop(false);
}),
new FlatButton(
child: new Text(StringsLocalization.yes()),
onPressed: positiveCallback)
]));
onPressed: () {
Navigator.of(context).pop(true);
})
])).then((b) {
if (b) {
helper.getToken().then((token) {
getDeleteTokenRequest(token).then((response) {
helper.clear().then((result) {
Navigator.of(context).pop(null);
});
}).catchError((error) {
print(error.toString());
Navigator.of(context).pop(null);
});
});
}
});
}
Widget getArrow() {

View File

@@ -34,7 +34,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
@override
void initState() {
showNextScreen();
init();
super.initState();
}
@@ -71,23 +71,27 @@ class _SplashScreenState extends BaseState<SplashScreen> {
]));
}
startRegistration(Widget screen) {
showNextScreen(Widget screen) {
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<String>(
builder: (BuildContext context) => screen, fullscreenDialog: true);
Navigator.of(context).push(route).then((token) {
_initAndStartScanner(context, app, token, helper);
if (token != null) {
_initAndStartScanner(context, app, token, helper);
} else {
showNextScreen(new RegistrationScreen(helper, app));
}
});
});
}
/// Запуск следующего экрана приложения.
showNextScreen() async {
init() async {
String token = await helper.getToken();
// В случае, если в приложении отсутствует токен,
// необходимо запустить регистрацию кассы.
if (token == null) {
startRegistration(new RegistrationScreen(helper, app));
showNextScreen(new RegistrationScreen(helper, app));
} else {
if (await platform.invokeMethod('isOnline')) {
getCheckTokenStatusRequest(token).then((statusResponse) {
@@ -106,7 +110,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
int code = statusResponse.statusCode;
if (code == 404) {
helper.clear().then((result) {
startRegistration(new RegistrationScreen(helper, app));
showNextScreen(new RegistrationScreen(helper, app));
});
} else {
Map status = JSON.decode(statusResponse.body);
@@ -138,7 +142,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
getCreateTokenRequest({'merchant_shop': merchantID, 'pos': posID})
.then((response) {
if (response.statusCode == 409) {
startRegistration(new FinishRegistrationScreen(helper, app));
showNextScreen(new FinishRegistrationScreen(helper, app));
} else if (response.statusCode == 201) {
clearToken(response, helper);
}
@@ -152,7 +156,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
helper.clear().then((_) {
Map parsedMap = JSON.decode(response.body);
getDeleteTokenRequest(parsedMap['token']).then((_) {
startRegistration(new RegistrationScreen(helper, app));
showNextScreen(new RegistrationScreen(helper, app));
}).catchError((error) {
print(error.toString());
});
@@ -220,7 +224,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
: JSON.encode(call.arguments[0]);
print(userString);
String card = call.arguments[1];
purchase(token, userString, card);
showNextScreen(new PurchaseScreen(helper, app, userString, card));
}
});
@@ -239,14 +243,4 @@ class _SplashScreenState extends BaseState<SplashScreen> {
});
});
}
purchase(String token, String userString, String card) {
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<Null>(
builder: (BuildContext context) => new PurchaseScreen(helper, app, userString, card), fullscreenDialog: true);
Navigator.of(context).push(route).then((_) {
_initAndStartScanner(context, app, token, helper);
});
});
}
}