Экран переключения валюты открывается с первого раза, соединение с базой данных не открывается на тех экранах, на которых это не требуется
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:checker/base/base_state.dart';
|
||||
import 'package:checker/common.dart';
|
||||
import 'package:checker/consts.dart';
|
||||
import 'package:checker/db.dart';
|
||||
import 'package:checker/network.dart';
|
||||
import 'package:checker/resources.dart';
|
||||
import 'package:checker/screens/finish_registration.dart';
|
||||
import 'package:checker/screens/registration.dart';
|
||||
import 'package:checker/strings.dart';
|
||||
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';
|
||||
import 'package:checker/network.dart';
|
||||
import 'package:checker/consts.dart';
|
||||
import 'package:checker/resources.dart';
|
||||
import 'package:checker/db.dart';
|
||||
import 'package:checker/base/base_state.dart';
|
||||
import 'package:checker/screens/registration.dart';
|
||||
import 'package:checker/screens/finish_registration.dart';
|
||||
|
||||
class SplashScreen extends StatefulWidget {
|
||||
@override State createState() => new _SplashScreenState();
|
||||
@@ -26,10 +27,9 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
@override void onStart() {
|
||||
helper.getSettings().then((info) {
|
||||
if (info == null) {
|
||||
platform.invokeMethod('getLocale').then((locale) {
|
||||
Intl.defaultLocale = locale;
|
||||
StringsLocalization.load(locale).then((l) {
|
||||
platform.invokeMethod('getCurrency').then((currency) {
|
||||
platform.invokeMethod('getCurrency').then((currency) {
|
||||
platform.invokeMethod('getLocale').then((locale) {
|
||||
initLocale(locale, () {
|
||||
helper.createAppInfo(locale, currency).then((_) {
|
||||
showNext();
|
||||
});
|
||||
@@ -38,8 +38,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
});
|
||||
} else {
|
||||
helper.getLocale().then((locale) {
|
||||
Intl.defaultLocale = locale;
|
||||
StringsLocalization.load(locale).then((l) {
|
||||
initLocale(locale, () {
|
||||
showNext();
|
||||
});
|
||||
});
|
||||
@@ -47,6 +46,13 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
void initLocale<T>(String locale, Future<T> onValue()) {
|
||||
Intl.defaultLocale = locale;
|
||||
StringsLocalization.load(locale).then((_) {
|
||||
onValue();
|
||||
});
|
||||
}
|
||||
|
||||
void showNext() {
|
||||
new Future.delayed(const Duration(milliseconds: 1000), () {
|
||||
showNextScreen();
|
||||
@@ -69,7 +75,8 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
bottom: 5.0),
|
||||
child: new Image.asset(powered_by_dinect_splash_png,
|
||||
height: 16.0,
|
||||
width: 122.0)))]);
|
||||
width: 122.0)))
|
||||
]);
|
||||
}
|
||||
|
||||
/// Возвращает столбец с логотипом приложения и текстом под ним.
|
||||
@@ -86,19 +93,18 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
new Image.asset(
|
||||
splash_text_png,
|
||||
height: 40.0,
|
||||
width: 240.0)]));
|
||||
width: 240.0)
|
||||
]));
|
||||
}
|
||||
|
||||
/// Запуск следующего экрана приложения.
|
||||
showNextScreen() async {
|
||||
|
||||
String token = await helper.getToken();
|
||||
|
||||
// В случае, если в приложении отсутствует токен,
|
||||
// необходимо запустить регистрацию кассы.
|
||||
if (token == null) {
|
||||
await helper.close();
|
||||
pushRouteReplacement(context, new RegistrationScreen());
|
||||
pushRouteReplacement(context, new RegistrationScreen(helper, app));
|
||||
} else {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
checkTokenStatus(token).then((statusResponse) {
|
||||
@@ -122,12 +128,9 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
|
||||
if (code == 404) {
|
||||
helper.clear().then((result) {
|
||||
helper.close().then((_) {
|
||||
pushRouteReplacement(context, new RegistrationScreen());
|
||||
});
|
||||
pushRouteReplacement(context, new RegistrationScreen(helper, app));
|
||||
});
|
||||
} else {
|
||||
|
||||
Map status = JSON.decode(statusResponse.body);
|
||||
bool active = status['active'] == null ? false : status['active'];
|
||||
|
||||
@@ -149,7 +152,6 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
/// Если вернулся код 200, значит токен был ранее удален и только что снова создался.
|
||||
/// Нужно удалить его и направить пользователя на экран регистрации.
|
||||
_createToken(SqliteHelper helper) async {
|
||||
|
||||
String merchantID = await helper.getMerchantID();
|
||||
String posID = await helper.getPosID();
|
||||
|
||||
@@ -165,13 +167,11 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
|
||||
/// Очищаем бд, делаем запрос на удаление токена.
|
||||
void clearToken(Response response, SqliteHelper helper) {
|
||||
|
||||
helper.clear().then((_) {
|
||||
Map parsedMap = JSON.decode(response.body);
|
||||
deleteToken(parsedMap['token']).then((_) {
|
||||
helper.close();
|
||||
Navigator.of(context).pop(); // Убираем текущий route
|
||||
pushRouteReplacement(context, new RegistrationScreen()); // Запускаем регистрацию
|
||||
Navigator.of(context).pop();
|
||||
pushRouteReplacement(context, new RegistrationScreen(helper, app));
|
||||
}).catchError((error) {
|
||||
helper.close();
|
||||
print(error.toString());
|
||||
|
||||
Reference in New Issue
Block a user