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

@@ -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);
});
});
}
}