В бд добавлена таблица настроек, данные для настроек берутся из базы

This commit is contained in:
Ivan Murashov
2017-09-08 17:25:56 +03:00
parent 29f6019caf
commit 0dc8ab5da0
16 changed files with 239 additions and 87 deletions

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:intl/intl.dart';
import 'dart:convert';
import 'dart:async';
import 'package:checker/common.dart';
@@ -17,6 +18,33 @@ class SplashScreen extends StatefulWidget {
class _SplashScreenState extends BaseState<SplashScreen> {
@override Widget getMainWidget() {
return getScreenContent();
}
@override void onStart() {
helper.getSettings().then((info) {
if (info == null) {
platform.invokeMethod('getLocale').then((locale) {
Intl.defaultLocale = locale;
platform.invokeMethod('getCurrency').then((currency) {
helper.createAppInfo(locale, currency).then((_) {
showNext();
});
});
});
} else {
showNext();
}
});
}
void showNext() {
new Future.delayed(const Duration(milliseconds: 1000), () {
showNextScreen();
});
}
@override
Widget getScreenContent() {
return app == null
@@ -36,21 +64,6 @@ class _SplashScreenState extends BaseState<SplashScreen> {
width: 122.0)))]);
}
@override Widget getMainWidget() {
return getScreenContent();
}
@override
String getTitle() {
return null;
}
@override void onStart() {
new Future.delayed(const Duration(milliseconds: 1000), () {
showNextScreen(context);
});
}
/// Возвращает столбец с логотипом приложения и текстом под ним.
/// Столбец занимает не все доступное пространство, а необходимый минимум в центре экрана.
getLogo() {
@@ -69,10 +82,10 @@ class _SplashScreenState extends BaseState<SplashScreen> {
}
/// Запуск следующего экрана приложения.
showNextScreen(BuildContext context) async {
showNextScreen() async {
String token = await helper.getToken();
// В случае, если в приложении отсутствует токен,
// необходимо запустить регистрацию кассы.
if (token == null) {
@@ -81,7 +94,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
} else {
if (await platform.invokeMethod('isOnline')) {
checkTokenStatus(token).then((statusResponse) {
handleStatusResponse(context, statusResponse, helper);
handleStatusResponse(statusResponse, helper);
}).catchError((error) {
helper.close().then((_) {
print(error.toString());
@@ -95,7 +108,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
/// Обработка ответа.
/// В случае, если токен был удален может прийти active: false, либо 404.
/// Если токен не активен, попробовать создать его еще раз.
handleStatusResponse(BuildContext context, var statusResponse, SqliteHelper helper) async {
handleStatusResponse(var statusResponse, SqliteHelper helper) async {
int code = statusResponse.statusCode;
print('resp: ${code}');
@@ -114,7 +127,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
startScanner(context, app, helper);
} else {
if (await platform.invokeMethod('isOnline')) {
_createToken(context, helper);
_createToken(helper);
}
}
}
@@ -127,7 +140,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
///
/// Если вернулся код 200, значит токен был ранее удален и только что снова создался.
/// Нужно удалить его и направить пользователя на экран регистрации.
_createToken(BuildContext ctx, SqliteHelper helper) async {
_createToken(SqliteHelper helper) async {
String merchantID = await helper.getMerchantID();
String posID = await helper.getPosID();
@@ -135,22 +148,22 @@ class _SplashScreenState extends BaseState<SplashScreen> {
createToken(merchantID, posID).then((response) {
if (response.statusCode == 409) {
helper.close();
pushRoute(ctx, new FinishRegistrationScreen());
pushRoute(context, new FinishRegistrationScreen());
} else if (response.statusCode == 201) {
clearToken(response, ctx, helper);
clearToken(response, helper);
}
}).catchError((error) => print(error.toString()));
}
/// Очищаем бд, делаем запрос на удаление токена.
void clearToken(Response response, BuildContext ctx, SqliteHelper helper) {
void clearToken(Response response, SqliteHelper helper) {
helper.clear().then((_) {
Map parsedMap = JSON.decode(response.body);
deleteToken(parsedMap['token']).then((_) {
helper.close();
Navigator.of(ctx).pop(); // Убираем текущий route
pushRoute(ctx, new RegistrationScreen()); // Запускаем регистрацию
Navigator.of(context).pop(); // Убираем текущий route
pushRoute(context, new RegistrationScreen()); // Запускаем регистрацию
}).catchError((error) {
helper.close();
print(error.toString());