From 7a1dc84fa10611b8989b7dd0cfb35cf23cd66594 Mon Sep 17 00:00:00 2001 From: Ivan Murashov Date: Tue, 26 Sep 2017 11:35:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=B0=D0=B4=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B8=D0=B7-=D0=B7=D0=B0=20=D0=BF=D0=BE=D0=BF=D1=8B=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=20=D0=BA=20=D0=B1=D0=B4,?= =?UTF-8?q?=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D0=B7=D0=B0=D0=BA=D1=80?= =?UTF-8?q?=D1=8B=D1=82=D0=B8=D1=8F=20=D1=81=D0=BE=D0=B5=D0=B4=D0=B8=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=20=D0=BD=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/src/main/AndroidManifest.xml | 1 + lib/common.dart | 18 +++++----- lib/db.dart | 3 -- lib/screens/settings.dart | 44 +++++++++++++++--------- lib/screens/splash.dart | 14 ++------ 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 97457a5..66ee409 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -46,6 +46,7 @@ \ No newline at end of file diff --git a/lib/common.dart b/lib/common.dart index 6d58d9c..6d8bfe2 100644 --- a/lib/common.dart +++ b/lib/common.dart @@ -40,11 +40,11 @@ logout(BuildContext context, SqliteHelper helper) async { if (token != null) { getDeleteTokenRequest(token).then((response) { helper.clear().then((result) { - helper.close().then((_) { +// helper.close().then((_) { Navigator.of(context).pop(); Navigator.of(context).pop(); pushRouteReplacement(context, new SplashScreen()); // Запускаем регистрацию - }); +// }); }); }).catchError((error) { print(error.toString()); @@ -63,12 +63,12 @@ forceLogout(String token , BuildContext context) async { SqliteHelper helper = new SqliteHelper(); helper.open().then((_) { helper.clear().then((_) { - helper.close().then((_) { +// helper.close().then((_) { while (Navigator.of(context).canPop()) { Navigator.of(context).pop(); } pushRouteReplacement(context, new SplashScreen()); - }); +// }); }); }); }).catchError((error) { @@ -117,8 +117,8 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async { } }); - helper.close().then((_){ - helper = null; +// helper.close().then((_){ +// helper = null; platform.invokeMethod('getEndpoint').then((endpoint) { platform.invokeMethod('getAppToken').then((appToken) async { platform.invokeMethod('startScanner', { @@ -126,13 +126,11 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async { 'url': endpoint, 'appToken': appToken, 'locale': Intl.defaultLocale, - 'color': Resources - .getPrimaryColor(app) - .value + 'color': Resources.getPrimaryColor(app).value }); }); }); - }); +// }); } } } diff --git a/lib/db.dart b/lib/db.dart index afaf00e..bcdb658 100644 --- a/lib/db.dart +++ b/lib/db.dart @@ -137,7 +137,4 @@ class SqliteHelper { Future clear() async { return await db.delete(tableSession, where: null); } - - Future close() async => db.close(); - } \ No newline at end of file diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 58f1ee7..c432033 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -28,10 +28,7 @@ class MenuItem { class SettingsState extends BaseState { - List menuItems = [ - new MenuItem('', ''), - new MenuItem('', '') - ]; + List menuItems; bool returnToScanner; @@ -42,14 +39,22 @@ class SettingsState extends BaseState { } @override Widget build(BuildContext ctx) { - helper.getSettings().then((info) { - setState(() { - menuItems[0].title = StringsLocalization.currency(); - menuItems[1].title = StringsLocalization.locale(); - menuItems[0].selectedValue = info['currency'].toString(); - menuItems[1].selectedValue = info['locale'] == null ? Intl.defaultLocale : info['locale'].toString(); + if (menuItems == null) { + menuItems = [ + new MenuItem('', ''), + new MenuItem('', '') + ]; + helper.getSettings().then((info) { + setState(() { + menuItems[0].title = StringsLocalization.currency(); + menuItems[1].title = StringsLocalization.locale(); + menuItems[0].selectedValue = info['currency'].toString(); + menuItems[1].selectedValue = + info['locale'] == null ? Intl.defaultLocale : info['locale'] + .toString(); + }); }); - }); + } return new WillPopScope(onWillPop: onWillPop, child: getMainWidget()); } @@ -72,11 +77,16 @@ class SettingsState extends BaseState { List getSettings() { List widgets = new List(); - for (int i = 0; i < menuItems.length; i++) { - if (menuItems[i].selectedValue != '') { - widgets.add(getSettingsItem(() => onPressed(menuItems.indexOf(menuItems[i])), - menuItems[i].title, - i == 0 ? getCurrencyTitle(int.parse(menuItems[i].selectedValue)) : getLocaleTitle(menuItems[i].selectedValue))); + if (menuItems != null) { + for (int i = 0; i < menuItems.length; i++) { + if (menuItems[i].selectedValue != '') { + widgets.add( + getSettingsItem(() => onPressed(menuItems.indexOf(menuItems[i])), + menuItems[i].title, + i == 0 ? getCurrencyTitle( + int.parse(menuItems[i].selectedValue)) : getLocaleTitle( + menuItems[i].selectedValue))); + } } } return widgets; @@ -105,8 +115,10 @@ class SettingsState extends BaseState { void onPressed(int position) { switch (position) { case 0 : + menuItems = null; return pushRoute(context, new CurrenciesScreen(helper, app)); case 1 : + menuItems = null; return pushRoute(context, new LanguagesScreen(helper, app)); } } diff --git a/lib/screens/splash.dart b/lib/screens/splash.dart index d77b1ed..45d5c3c 100644 --- a/lib/screens/splash.dart +++ b/lib/screens/splash.dart @@ -129,7 +129,7 @@ class _SplashScreenState extends BaseState { getCheckTokenStatusRequest(token).then((statusResponse) { handleStatusResponse(statusResponse, helper); }).catchError((error) { - handleError(error.toString()); + print(error.toString()); }); } } @@ -179,7 +179,7 @@ class _SplashScreenState extends BaseState { clearToken(response, helper); } }).catchError((error) { - handleError(error.toString()); + print(error.toString()); }); } @@ -191,16 +191,8 @@ class _SplashScreenState extends BaseState { Navigator.of(context).pop(); pushRouteReplacement(context, new RegistrationScreen(helper, app)); }).catchError((error) { - handleError(error.toString()); + print(error.toString()); }); }); } - - /// Закрываем соединение, логируем ошибку. - void handleError(String error) { - helper.close().then((_) { - print(error.toString()); - return false; - }); - } }