diff --git a/ios/Flutter/app.flx b/ios/Flutter/app.flx index b9fa089..4605962 100644 Binary files a/ios/Flutter/app.flx and b/ios/Flutter/app.flx differ diff --git a/ios/Runner.xcworkspace/xcuserdata/kifio.xcuserdatad/UserInterfaceState.xcuserstate b/ios/Runner.xcworkspace/xcuserdata/kifio.xcuserdatad/UserInterfaceState.xcuserstate index a9a7349..d053612 100644 Binary files a/ios/Runner.xcworkspace/xcuserdata/kifio.xcuserdatad/UserInterfaceState.xcuserstate and b/ios/Runner.xcworkspace/xcuserdata/kifio.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/lib/base/base_state.dart b/lib/base/base_state.dart index 78e7829..afcd50c 100644 --- a/lib/base/base_state.dart +++ b/lib/base/base_state.dart @@ -98,7 +98,12 @@ abstract class BaseState extends State { 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(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: { diff --git a/lib/screens/purchase.dart b/lib/screens/purchase.dart index e625cce..52f969a 100644 --- a/lib/screens/purchase.dart +++ b/lib/screens/purchase.dart @@ -404,7 +404,7 @@ class PurchaseScreenState extends BaseState { new Future.delayed(const Duration(milliseconds: 200), () { print('show purchase success!'); - var route = new MaterialPageRoute(builder: (BuildContext context) => new PurchaseSuccessScreen( + var route = new MaterialPageRoute(builder: (BuildContext context) => new PurchaseSuccessScreen( sumTotal, user['first_name'] == null ? '' : user['first_name'], helper, @@ -412,8 +412,8 @@ class PurchaseScreenState extends BaseState { 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); }); }); } diff --git a/lib/screens/purchase_success.dart b/lib/screens/purchase_success.dart index bbd7576..9bd5cfd 100644 --- a/lib/screens/purchase_success.dart +++ b/lib/screens/purchase_success.dart @@ -122,9 +122,10 @@ class PurchaseSuccessScreenState extends BaseState { 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)); } diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 41e8cfa..a6f2ea6 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -160,38 +160,14 @@ class SettingsState extends BaseState { } // В методе отправляется запрос на удаление токена кассы, очищаются 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(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( context: context, child: new AlertDialog( title: new Text(title), @@ -200,12 +176,27 @@ class SettingsState extends BaseState { 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() { diff --git a/lib/screens/splash.dart b/lib/screens/splash.dart index f07f5c4..ffbe636 100644 --- a/lib/screens/splash.dart +++ b/lib/screens/splash.dart @@ -34,7 +34,7 @@ class _SplashScreenState extends BaseState { @override void initState() { - showNextScreen(); + init(); super.initState(); } @@ -71,23 +71,27 @@ class _SplashScreenState extends BaseState { ])); } - startRegistration(Widget screen) { + showNextScreen(Widget screen) { new Future.delayed(const Duration(milliseconds: 200), () { var route = new MaterialPageRoute( 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 { 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 { 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 { 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 { : 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 { }); }); } - - purchase(String token, String userString, String card) { - new Future.delayed(const Duration(milliseconds: 200), () { - var route = new MaterialPageRoute( - builder: (BuildContext context) => new PurchaseScreen(helper, app, userString, card), fullscreenDialog: true); - Navigator.of(context).push(route).then((_) { - _initAndStartScanner(context, app, token, helper); - }); - }); - } }