Небольшие исправления

This commit is contained in:
Ivan Murashov
2017-07-24 19:45:04 +03:00
parent 080c7ec471
commit ff0573d65d
5 changed files with 69 additions and 87 deletions

View File

@@ -11,12 +11,12 @@ class FinishRegistrationScreen extends StatefulWidget {
class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> { class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
bool _tokenActive = true; bool _tokenActive = false;
String _merchantID = ''; String _merchantID = '';
_RegistrationScreenState() { _RegistrationScreenState() {
if (textFieldValue == "") { if (textFieldValue == "") {
_getSavedMerchantID(); getSavedMerchantID();
} }
} }
@@ -37,17 +37,39 @@ class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
getLogo(), getLogo(),
getHintLabel(), getHintLabel(),
getDecoratedTextWidget(), getDecoratedTextWidget(),
_getMessage(), getMessage(),
buildButton(new EdgeInsets.only(top: 36.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildButton(new EdgeInsets.only(top: 36.0, left: buttonVerticalMargin, right: buttonVerticalMargin),
buildRaisedButton(context, _tokenActive ? 'ЗАВЕРШИТЬ РЕГИСТРАЦИЮ' : 'ОБНОВИТЬ СТАТУС АКТИВАЦИИ',() => startScanner(context))) buildRaisedButton(context, _tokenActive ? 'ЗАВЕРШИТЬ РЕГИСТРАЦИЮ' : 'ОБНОВИТЬ СТАТУС АКТИВАЦИИ', () => handleTap()))
]); ]);
} }
handleTap() {
if (_tokenActive) {
startScanner(context);
} else {
checkToken(context).then((response) {
print(response.body);
Map parsedMap = JSON.decode(response.body);
// Обновить экран, заменить сообщение о необходимости активации токена, на сообщние о том, что токен активен.
setState(() {
_tokenActive = parsedMap['active'];
});
}).catchError((error) {
print(error.toString());
return false;
});
}
}
@override Widget getTextWidget() { @override Widget getTextWidget() {
return new Row(children: <Widget>[new Text(_merchantID != null ? _merchantID : '', style: new TextStyle(color: Colors.black, fontSize: 16.0))]); return new Row(children: <Widget>[new Text(_merchantID != null ? _merchantID : '', style: new TextStyle(color: Colors.black, fontSize: 16.0))]);
} }
_getSavedMerchantID() { /// Достаем сохраненный в SharedPreferences merchantID.
getSavedMerchantID() {
platform.invokeMethod('getMerchantID').then((result) { platform.invokeMethod('getMerchantID').then((result) {
setState(() { setState(() {
_merchantID = result; _merchantID = result;
@@ -56,54 +78,29 @@ class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
}); });
} }
_getMessage() { /// Метод возвращает контейнер с текстом сообщения и бэкграундом.
getMessage() {
return new Container(height: _tokenActive ? 72.0 : 108.0, decoration: _getDecoraionForMessageField(), return new Container(height: _tokenActive ? 72.0 : 108.0, decoration: _getDecoraionForMessageField(),
margin: new EdgeInsets.only(top: 20.0, left: 12.0, right: 12.0), margin: new EdgeInsets.only(top: 20.0, left: 12.0, right: 12.0),
padding: new EdgeInsets.only(bottom: 22.0, left: 14.0, right: 14.0), padding: new EdgeInsets.only(bottom: 22.0, left: 14.0, right: 14.0),
child: new Center(child: new Text(_getMessageText(), child: new Center(child: getMessageTextWidget()));
textAlign: TextAlign.center, style: new TextStyle(height: 1.5, fontWeight: FontWeight.bold, fontSize: 14.0, color: _tokenActive ? tokenActiveTextColor : tokenActivateTextColor))));
} }
_getMessageText() { /// Метод возвращает виджет с текстом сообщения, всеми его привязками и стилями.
getMessageTextWidget() {
return new Text(getMessageString(), textAlign: TextAlign.center,
style: new TextStyle(height: 1.5, fontWeight: FontWeight.bold, fontSize: 14.0,
color: _tokenActive ? tokenActiveTextColor : tokenActivateTextColor));
}
/// Получаем текст сообщения, в зависимости от статуса активации.
getMessageString() {
return _tokenActive ? 'Программа активирована' : 'Запрос на активацию программы отправлен, дождитесь подтверждения активации администратором'; return _tokenActive ? 'Программа активирована' : 'Запрос на активацию программы отправлен, дождитесь подтверждения активации администратором';
} }
/// Фоновое изображение для сообщения.
Decoration _getDecoraionForMessageField() { Decoration _getDecoraionForMessageField() {
return new BoxDecoration(image: new DecorationImage( return new BoxDecoration(image: new DecorationImage(
image: new ExactAssetImage(_tokenActive ? active_token_bg_png : activate_token_bg_png), fit: _tokenActive ? BoxFit.fitWidth : BoxFit.fill)); image: new ExactAssetImage(_tokenActive ? active_token_bg_png : activate_token_bg_png), fit: _tokenActive ? BoxFit.fitWidth : BoxFit.fill));
} }
/// Метод возвращает кнопку, которая запускает отправку токена кассы на сервер.
_getButton(BuildContext context) {
double buttonHeight = 42.0;
double topMargin = 8.0;
return new Container(margin: new EdgeInsets.only(top: topMargin), height: buttonHeight,
child: new RaisedButton(child: new Text(,
style: new TextStyle(fontSize: 14.0, color: Colors.white)),
onPressed: () {
startScanner(context);
// if (_tokenActive) {
// startScanner(context);
// } else {
// checkToken(context).then((response) {
// print(response.body);
// Map parsedMap = JSON.decode(response.body);
// // Обновить экран, заменить сообщение о необходимости активации токена, на сообщние о том, что токен активен.
// setState(() {
// _tokenActive = parsedMap['active'];
// });
// }).catchError((error) {
// print(error.toString());
// return false;
// });
// }
},
color: primaryColor));
}
} }

View File

@@ -28,14 +28,13 @@ const String active_token_bg_png = 'assets/active_token_message_background.png';
const Color primaryColor = const Color(0xffeb0004); const Color primaryColor = const Color(0xffeb0004);
const Color greyTextColor = const Color(0xffa5a5a5); const Color greyTextColor = const Color(0xffa5a5a5);
const Color textBorderColor = const Color(0xffcfd8dc); const Color textBorderColor = const Color(0xffcfd8dc);
const Color textFieldBackground = const Color(0xffefefef);
const Color tokenActiveTextColor = const Color(0xff1f5a1f); const Color tokenActiveTextColor = const Color(0xff1f5a1f);
const Color tokenActivateTextColor = const Color(0xff4e3a19); const Color tokenActivateTextColor = const Color(0xff4e3a19);
const Color greenBackground = const Color(0xff8ae28a); const Color greenBackground = const Color(0xff8ae28a);
// Dimens // Dimens
const double verticalMargin = 28.0; const double verticalMargin = 28.0;
const double buttonVerticalMargin = 64.0; const double buttonVerticalMargin = 42.0;
const double buttonHeight = 48.0; const double buttonHeight = 48.0;
const double iconHeight = 20.0; const double iconHeight = 20.0;
@@ -81,7 +80,7 @@ startScanner(BuildContext context) async {
logout(BuildContext context) { logout(BuildContext context) {
String url = intUrl + 'tokens/' + 'khooi' + '?_dmapptoken=' + intToken; String url = intUrl + 'tokens/' + token + '?_dmapptoken=' + intToken;
print(url); print(url);
httpClient.delete(url).then((response) { httpClient.delete(url).then((response) {
print(response.body); print(response.body);

View File

@@ -14,6 +14,10 @@ class PurchaseScreen extends StatefulWidget {
class PurchaseScreenState<T> extends BaseState<T> { class PurchaseScreenState<T> extends BaseState<T> {
PurchaseScreenState() {
}
String integerPart = '', fractionalPart = ''; String integerPart = '', fractionalPart = '';
@override String getTitle() { @override String getTitle() {

View File

@@ -48,7 +48,7 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
return textFieldValue.length > 0 && textFieldValue.length < 25; return textFieldValue.length > 0 && textFieldValue.length < 25;
} }
/// Показать индикатор, запросить токен. /// Показать progressBar, запросить токен.
_registerShop(BuildContext context) { _registerShop(BuildContext context) {
setState(() { setState(() {
loading = true; loading = true;
@@ -56,14 +56,6 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
}); });
} }
/// Экран зависает на 1 сек, после этого выполняется переход на экран потверждения токена.
_registerDemo(BuildContext context) {
new Future.delayed(const Duration(milliseconds: 1000), () {
loading = false;
pushRoute(context, new FinishRegistrationScreen());
});
}
/// Получение от платформы id установки, формирование запроса на получение токена, сохранение токена. /// Получение от платформы id установки, формирование запроса на получение токена, сохранение токена.
_register(BuildContext context) async { _register(BuildContext context) async {
@@ -76,33 +68,27 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
'pos': pos, 'pos': pos,
}; };
pushRoute(context, new FinishRegistrationScreen()); httpClient.post(url, body: body).then((response) {
// httpClient.post(url, body: body).then((response) {
setState(() { setState(() {
error = null; error = null;
loading = false;
}); });
// print(response.body); print(response.body);
// Map parsedMap = JSON.decode(response.body); Map parsedMap = JSON.decode(response.body);
// setState(() { if (response.statusCode == 201) {
// loading = false; token = parsedMap['token'];
// }); platform.invokeMethod('saveToken', {'token' : token});
// if (response.statusCode == 201) { platform.invokeMethod('saveMerchantID', {'merchantID' : textFieldValue});
// token = parsedMap['token']; pushRoute(context, new FinishRegistrationScreen());
// platform.invokeMethod('saveToken', {'token' : token}); } else {
// platform.invokeMethod('saveMerchantID', {'merchantID' : merchantID}); setState(() {
// pushRoute(context, new FinishRegistrationScreen()); error = parsedMap['errors'][0];
// } else { });
// setState(() { }
// error = parsedMap['errors'][0]; }).catchError((error) {
// }); print(error.toString());
// } });
// }).catchError((error) {
// setState(() {
// error = 'Отсутствует интернет соединение';
// });
// });
} }
} }

View File

@@ -13,27 +13,22 @@ class SplashScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Splash скрин зависает мимнимум на 1 секунду. // Появляется splash screen, проверяется токен.
// После этого начинается проверка токена. new Future.delayed(const Duration(milliseconds: 500), () {
showNextScreen(context);
new Future.delayed(const Duration(milliseconds: 1000), () {
pushRoute(context, new PurchaseScreen());
// _showNextScreen(context);
}); });
return new Image.asset(splash_png, fit: BoxFit.cover); return new Image.asset(splash_png, fit: BoxFit.cover);
} }
/// Запуск следующего экрана приложения. /// Запуск следующего экрана приложения.
_showNextScreen(BuildContext context) async { showNextScreen(BuildContext context) async {
const platform = const MethodChannel('com.dinect.checker/instance_id');
token = await platform.invokeMethod('getToken'); token = await platform.invokeMethod('getToken');
print('token: $token'); print('token: $token');
// В случае, если в приложении отсутствует токен, // В случае, если в приложении отсутствует токен,
// необходимо запустить регистрацию кассы. // необходимо запустить регистрацию кассы.
if (token == null) { if (token == null) {
pushRoute(context, new RegistrationScreen()); pushRoute(context, new RegistrationScreen());
} else { } else {
@@ -41,6 +36,7 @@ class SplashScreen extends StatelessWidget {
checkToken(context).then((response) { checkToken(context).then((response) {
print(response.body); print(response.body);
Map parsedMap = JSON.decode(response.body); Map parsedMap = JSON.decode(response.body);
bool active = parsedMap['active']; bool active = parsedMap['active'];