Регистрация, проверка токена, обработка ошибок, сканирование
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'main.dart';
|
||||
import 'dart:convert'; // Пакет для обработки json с ответом от сервера.
|
||||
|
||||
/// TODO: Вот это все ерунда конечно, это должно обрабатыватсья через state экрана регистрации.
|
||||
|
||||
/// Экран регистрации магазина и кассы.
|
||||
class FinishRegistrationScreen extends StatefulWidget {
|
||||
@override State createState() => new _RegistrationScreenState();
|
||||
}
|
||||
|
||||
class _RegistrationScreenState extends State<FinishRegistrationScreen> {
|
||||
|
||||
bool _tokenActive = false;
|
||||
String _merchantID = null;
|
||||
|
||||
@override Widget build(BuildContext context) {
|
||||
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
|
||||
}
|
||||
|
||||
AppBar _getAppBar() {
|
||||
return new AppBar(title: new Text("Регистрация магазина"),
|
||||
return new AppBar(title: new Text("Регистрация", style: new TextStyle(fontSize: 18.0)),
|
||||
backgroundColor: primaryColor, actions: <Widget>[
|
||||
new IconButton(
|
||||
icon: new Icon(Icons.help_outline),
|
||||
@@ -23,67 +28,97 @@ class _RegistrationScreenState extends State<FinishRegistrationScreen> {
|
||||
}
|
||||
|
||||
Widget _getScreen(BuildContext context) {
|
||||
return new Center(child: new Column(children: <Widget>[
|
||||
if (_merchantID == null) {
|
||||
_getSavedMerchantID();
|
||||
}
|
||||
return new Column(children: <Widget>[
|
||||
_getLogo(),
|
||||
_getMerchantIDTitle(),
|
||||
_getDecoratedText(),
|
||||
_getMessage(),
|
||||
_getButton(context)
|
||||
]));
|
||||
]);
|
||||
}
|
||||
|
||||
Container _getLogo() {
|
||||
return new Container(padding: new EdgeInsets.only(top: 16.0, bottom: 16.0),
|
||||
child: new Image.asset(logo_png, height: 24.0, width: 156.0));
|
||||
_getLogo() {
|
||||
double containerHeight = 92.0;
|
||||
double imageWidth = 156.0;
|
||||
return new Container(height: containerHeight, child: new Image.asset(logo_png, width: imageWidth));
|
||||
}
|
||||
|
||||
Container _getDecoratedText() {
|
||||
_getMerchantIDTitle() {
|
||||
return new Container(margin: new EdgeInsets.only(top: 8.0, bottom: 8.0, left: 28.0, right: 28.0),
|
||||
child: new Row(crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[new Text('ID Магазина', textAlign: TextAlign.left, style: new TextStyle(fontWeight: FontWeight.w300, color: greyTextColor, fontSize: 14.0))]));
|
||||
}
|
||||
|
||||
_getDecoratedText() {
|
||||
return new Container(margin: new EdgeInsets.only(left: 28.0, right: 28.0),
|
||||
padding: new EdgeInsets.only(top: 12.0, bottom: 12.0, left: 16.0, right: 16.0),
|
||||
decoration: _getDecoraionForMerchantId(),
|
||||
child: _getMerchantIDText());
|
||||
child: new Row(children: <Widget>[_getMerchantIDText()]));
|
||||
}
|
||||
|
||||
Text _getMerchantIDText() {
|
||||
return new Text(merchantID, style: new TextStyle(color: const Color(0xffa5a5a5), fontSize: 16.0));
|
||||
_getMerchantIDText() {
|
||||
return new Text(_merchantID != null ? _merchantID : '', style: new TextStyle(color: Colors.black, fontSize: 16.0));
|
||||
}
|
||||
|
||||
_getSavedMerchantID() {
|
||||
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
||||
platform.invokeMethod('getMerchantID').then((result) {
|
||||
setState(() {
|
||||
_merchantID = result;
|
||||
print(_merchantID);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Container _getMessage() {
|
||||
return new Container(padding: new EdgeInsets.only(top: 20.0, left: 26.0, right: 26.0),
|
||||
child: new Container(height: 128.0, decoration: _getDecoraionForMessageField(),
|
||||
padding: new EdgeInsets.only(top: 16.0, bottom: 8.0, left: 28.0, right: 28.0),
|
||||
child: new Text('Запрос на активацию программы отправлен, дождrитесь подтверждения активации администратором',
|
||||
textAlign: TextAlign.center, style: new TextStyle(fontWeight: FontWeight.bold, color: const Color(0xff4e3a19)))));
|
||||
return new Container(height: _tokenActive ? 72.0 : 108.0, decoration: _getDecoraionForMessageField(),
|
||||
margin: new EdgeInsets.only(top: 20.0, left: 12.0, right: 12.0),
|
||||
padding: new EdgeInsets.only(bottom: 16.0, left: 14.0, right: 14.0),
|
||||
child: new Center(child: new Text(_tokenActive ? 'Программа активирована' : 'Запрос на активацию программы отправлен, дождитесь подтверждения активации администратором',
|
||||
textAlign: TextAlign.center, style: new TextStyle(height: 1.5, fontWeight: FontWeight.bold, fontSize: 14.0, color: _tokenActive ? tokenActiveTextColor : tokenActivateTextColor))));
|
||||
}
|
||||
|
||||
Decoration _getDecoraionForMessageField() {
|
||||
return new BoxDecoration(image: new DecorationImage(
|
||||
image: new ExactAssetImage(activate_token_bg_png), fit: BoxFit.fill));
|
||||
image: new ExactAssetImage(_tokenActive ? active_token_bg_png : activate_token_bg_png), fit: _tokenActive ? BoxFit.fitWidth : BoxFit.fill));
|
||||
}
|
||||
|
||||
Decoration _getDecoraionForMerchantId() {
|
||||
return new BoxDecoration(color: Colors.white,
|
||||
return new BoxDecoration(color: textFieldBackground,
|
||||
border: new Border.all(color: const Color(0xffcfd8dc), width: 1.0),
|
||||
borderRadius: new BorderRadius.all(new Radius.circular(4.0)));
|
||||
}
|
||||
|
||||
Container _getButton(BuildContext context) {
|
||||
return new Container(padding: new EdgeInsets.only(top: 36.0),
|
||||
child: new Container(height: 64.0, padding: new EdgeInsets.all(8.0),
|
||||
child: new RaisedButton(child: new Text('Обновить статус активации',
|
||||
style: new TextStyle(color: Colors.white)),
|
||||
onPressed: () {
|
||||
startScanner(context);
|
||||
})));
|
||||
/// Метод возвращает кнопку, которая запускает отправку токена кассы на сервер.
|
||||
_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(_tokenActive ? 'ЗАВЕРШИТЬ РЕГИСТРАЦИЮ' : 'ОБНОВИТЬ СТАТУС АКТИВАЦИИ',
|
||||
style: new TextStyle(fontSize: 14.0, color: Colors.white)),
|
||||
onPressed: () {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
_checkToken(BuildContext context) {
|
||||
checkToken(context, new CheckTokenCallback());
|
||||
}
|
||||
|
||||
class CheckTokenCallback extends Callback {
|
||||
|
||||
call(BuildContext context) {
|
||||
startScanner();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user