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

Binary file not shown.

View File

@@ -98,7 +98,12 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
void onOptionsItemClick(int index) { void onOptionsItemClick(int index) {
switch (index) { switch (index) {
case 0: { 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; break;
} }
case 1: { case 1: {

View File

@@ -404,7 +404,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
new Future.delayed(const Duration(milliseconds: 200), () { new Future.delayed(const Duration(milliseconds: 200), () {
print('show purchase success!'); 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, sumTotal,
user['first_name'] == null ? '' : user['first_name'], user['first_name'] == null ? '' : user['first_name'],
helper, helper,
@@ -412,8 +412,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
purchase, purchase,
coupons['results'] coupons['results']
), fullscreenDialog: true); ), fullscreenDialog: true);
Navigator.of(context).push(route).then((_) { Navigator.of(context).push(route).then((token) {
Navigator.of(context).pop(); 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); return new EdgeInsets.only(bottom: bottom, left: side, right: side);
} }
getScanButton() { getScanButton() async {
String title = StringsLocalization.scan(); 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 приложения. // В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения.
logout(BuildContext context, SqliteHelper helper) async { logout(BuildContext context, SqliteHelper helper) {
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();
}
}
};
showYesNoDialog(context, StringsLocalization.confirmation(), showYesNoDialog(context, StringsLocalization.confirmation(),
StringsLocalization.askChangeStore(), positiveCallback); StringsLocalization.askChangeStore());
} }
// Запуск диалога с двумя кнопками // Запуск диалога с двумя кнопками
showYesNoDialog(BuildContext context, String title, String content, showYesNoDialog(BuildContext context, String title, String content) {
VoidCallback positiveCallback) { showDialog<bool>(
showDialog(
context: context, context: context,
child: new AlertDialog( child: new AlertDialog(
title: new Text(title), title: new Text(title),
@@ -200,12 +176,27 @@ class SettingsState extends BaseState<SettingsScreen> {
new FlatButton( new FlatButton(
child: new Text(StringsLocalization.no()), child: new Text(StringsLocalization.no()),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop(false);
}), }),
new FlatButton( new FlatButton(
child: new Text(StringsLocalization.yes()), 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() { Widget getArrow() {

View File

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