Исправлено падение приложения из-за попытки сделать запрос к бд, после закрытия соединения с ней

This commit is contained in:
Ivan Murashov
2017-09-26 11:35:30 +03:00
parent 9f2bf14199
commit 7a1dc84fa1
5 changed files with 40 additions and 40 deletions

View File

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

View File

@@ -137,7 +137,4 @@ class SqliteHelper {
Future clear() async {
return await db.delete(tableSession, where: null);
}
Future close() async => db.close();
}

View File

@@ -28,10 +28,7 @@ class MenuItem {
class SettingsState extends BaseState<SettingsScreen> {
List<MenuItem> menuItems = [
new MenuItem('', ''),
new MenuItem('', '')
];
List<MenuItem> menuItems;
bool returnToScanner;
@@ -42,14 +39,22 @@ class SettingsState extends BaseState<SettingsScreen> {
}
@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<SettingsScreen> {
List<Widget> getSettings() {
List<Widget> 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<SettingsScreen> {
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));
}
}

View File

@@ -129,7 +129,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
getCheckTokenStatusRequest(token).then((statusResponse) {
handleStatusResponse(statusResponse, helper);
}).catchError((error) {
handleError(error.toString());
print(error.toString());
});
}
}
@@ -179,7 +179,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
clearToken(response, helper);
}
}).catchError((error) {
handleError(error.toString());
print(error.toString());
});
}
@@ -191,16 +191,8 @@ class _SplashScreenState extends BaseState<SplashScreen> {
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;
});
}
}