Упрощена работа с локалью, базовый url и токен приложения вынесены в build.gradle, добавлен конфиг для разработки и тестирования, исправлена проблема с переходом на экран сканера если локаль не выбиралась в настройках

This commit is contained in:
kifio
2017-09-23 23:19:32 +03:00
parent 808d5a39e5
commit 40fed84275
15 changed files with 277 additions and 255 deletions

View File

@@ -15,12 +15,13 @@ import 'package:http/http.dart';
import 'package:intl/intl.dart';
class SplashScreen extends StatefulWidget {
@override State createState() => new _SplashScreenState();
@override
State createState() => new _SplashScreenState();
}
class _SplashScreenState extends BaseState<SplashScreen> {
@override Widget build(BuildContext ctx) {
@override
Widget build(BuildContext ctx) {
if (helper == null) {
helper = new SqliteHelper();
helper.open().then((_) {
@@ -42,7 +43,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
if (locale == null) {
initWithSystemValue();
} else {
initWithSavedValue();
initWithSavedValue(locale);
}
});
}
@@ -61,17 +62,15 @@ class _SplashScreenState extends BaseState<SplashScreen> {
});
}
void initWithSavedValue() {
helper.getLocale().then((locale) {
initLocale(locale, () {
showNext();
});
void initWithSavedValue(String locale) {
initLocale(locale, () {
showNext();
});
}
void createSettingsTable(String locale) {
platform.invokeMethod('getCurrency').then((currency) {
helper.createAppInfo(locale, currency);
helper.createAppInfo(currency);
initLocale(locale, () {
showNext();
});
@@ -95,44 +94,31 @@ class _SplashScreenState extends BaseState<SplashScreen> {
Widget getScreenContent() {
return app == null
? getBackground()
: new Stack(
children: <Widget>[
getBackground(),
getLogo(),
new Align(
alignment: FractionalOffset.bottomRight,
child: new Container(
margin: new EdgeInsets.only(
right: 11.0,
bottom: 5.0),
child: new Image.asset(powered_by_dinect_splash_png,
height: 16.0,
width: 122.0)))
]);
: new Stack(children: <Widget>[
getBackground(),
getLogo(),
new Align(
alignment: FractionalOffset.bottomRight,
child: new Container(
margin: new EdgeInsets.only(right: 11.0, bottom: 5.0),
child: new Image.asset(powered_by_dinect_splash_png,
height: 16.0, width: 122.0)))
]);
}
/// Возвращает столбец с логотипом приложения и текстом под ним.
/// Столбец занимает не все доступное пространство, а необходимый минимум в центре экрана.
getLogo() {
return new Center(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Image.asset(
Resources.getLogo(app),
height: 112.0,
width: 252.0),
new Image.asset(
splash_text_png,
height: 40.0,
width: 240.0)
]));
child: new Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
new Image.asset(Resources.getLogo(app), height: 112.0, width: 252.0),
new Image.asset(splash_text_png, height: 40.0, width: 240.0)
]));
}
/// Запуск следующего экрана приложения.
showNextScreen() async {
String token = await helper.getToken();
String locale = await helper.getLocale();
// В случае, если в приложении отсутствует токен,
// необходимо запустить регистрацию кассы.
@@ -140,7 +126,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
pushRouteReplacement(context, new RegistrationScreen(helper, app));
} else {
if (await platform.invokeMethod('isOnline')) {
checkTokenStatus(token, locale).then((statusResponse) {
getCheckTokenStatusRequest(token).then((statusResponse) {
handleStatusResponse(statusResponse, helper);
}).catchError((error) {
handleError(error.toString());
@@ -183,11 +169,12 @@ class _SplashScreenState extends BaseState<SplashScreen> {
_createToken(SqliteHelper helper) async {
String merchantID = await helper.getMerchantID();
String posID = await helper.getPosID();
String locale = await helper.getLocale();
createToken(merchantID, posID, locale).then((response) {
getCreateTokenRequest({'merchant_shop': merchantID, 'pos': posID})
.then((response) {
if (response.statusCode == 409) {
pushRouteReplacement(context, new FinishRegistrationScreen(helper, app));
pushRouteReplacement(
context, new FinishRegistrationScreen(helper, app));
} else if (response.statusCode == 201) {
clearToken(response, helper);
}
@@ -198,10 +185,9 @@ class _SplashScreenState extends BaseState<SplashScreen> {
/// Очищаем бд, делаем запрос на удаление токена.
Future clearToken(Response response, SqliteHelper helper) async {
String locale = await helper.getLocale();
helper.clear().then((_) {
Map parsedMap = JSON.decode(response.body);
deleteToken(parsedMap['token'], locale).then((_) {
getDeleteTokenRequest(parsedMap['token']).then((_) {
Navigator.of(context).pop();
pushRouteReplacement(context, new RegistrationScreen(helper, app));
}).catchError((error) {