Добавлена проверка статуса токена, обработка статуса токена
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'main.dart';
|
||||
import 'activate_token.dart';
|
||||
|
||||
/// Экран регистрации магазина и кассы.
|
||||
class RegistrationScreen extends StatefulWidget {
|
||||
@@ -9,14 +11,11 @@ class RegistrationScreen extends StatefulWidget {
|
||||
|
||||
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
|
||||
static const String _merchantIDHint = 'ID магазина';
|
||||
static const String _posIDHint = 'Номер кассы';
|
||||
|
||||
String _merchantID = "";
|
||||
String _posID = "";
|
||||
|
||||
@override Widget build(BuildContext context) {
|
||||
return new Scaffold(appBar: _getAppBar(), body: _getScreen());
|
||||
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
|
||||
}
|
||||
|
||||
AppBar _getAppBar() {
|
||||
@@ -35,25 +34,19 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
]);
|
||||
}
|
||||
|
||||
Widget _getScreen() {
|
||||
return new Center(child: new Column(children: _getChildren()));
|
||||
Widget _getScreen(BuildContext context) {
|
||||
return new Center(child: new Column(children: <Widget>[
|
||||
_getLogo(),
|
||||
_getDecoratedInputField(merchantIDHint, 0.0),
|
||||
_getDecoratedInputField(posIDHint, 36.0),
|
||||
_getButton(context)
|
||||
]));
|
||||
}
|
||||
|
||||
List<Widget> _getChildren() {
|
||||
return<Widget>[
|
||||
_getLogo(),
|
||||
_getDecoratedInputField(_merchantIDHint, 0.0),
|
||||
_getDecoratedInputField(_posIDHint, 36.0),
|
||||
_getButton()
|
||||
];
|
||||
}
|
||||
|
||||
Container _getLogo() {
|
||||
return new Container(height: 192.0,
|
||||
child: new Center(
|
||||
child: new Image.asset('assets/registration_logo.png',
|
||||
height: 24.0,
|
||||
width: 156.0)));
|
||||
child: new Image.asset(logo_png, height: 24.0, width: 156.0));
|
||||
}
|
||||
|
||||
Container _getDecoratedInputField(String hint, double topPadding) {
|
||||
@@ -75,9 +68,9 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
void _handleUserInput(String hint, String text) {
|
||||
if (text.length > 0) {
|
||||
setState(() {
|
||||
if (hint == _merchantIDHint)
|
||||
if (hint == merchantIDHint)
|
||||
_merchantID = text;
|
||||
else if (hint == _posIDHint)
|
||||
else if (hint == posIDHint)
|
||||
_posID = text;
|
||||
});
|
||||
}
|
||||
@@ -90,13 +83,14 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
borderRadius: new BorderRadius.all(new Radius.circular(4.0)));
|
||||
}
|
||||
|
||||
Container _getButton() {
|
||||
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: _isFieldsAreFilled() ? () => _register(_merchantID) : null,
|
||||
disabledColor: const Color(0xffbfbfbf))));
|
||||
onPressed: _isFieldsAreFilled() ? () => _registerShop(context, _merchantID) : null,
|
||||
disabledColor: const Color(0xffbfbfbf),
|
||||
color: const Color(0xff3078c0))));
|
||||
}
|
||||
|
||||
_isFieldsAreFilled() {
|
||||
@@ -105,9 +99,13 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
return _merchantID.length == 5 && _posID.length > 0;
|
||||
}
|
||||
|
||||
_register(String merchantShop) async {
|
||||
void _registerShop(BuildContext context, String merchantShop) {
|
||||
_register(context, merchantShop);
|
||||
}
|
||||
|
||||
const platform = const MethodChannel('com.dinnect.checker/instance_id');
|
||||
_register(BuildContext context, String merchantShop) async {
|
||||
|
||||
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
||||
String url = intUrl + 'tokens/?_dmapptoken=' + intToken;
|
||||
String pos = await platform.invokeMethod('getInstanceID');
|
||||
print(pos);
|
||||
@@ -127,6 +125,12 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
|
||||
httpClient.post(url, body: body).then((response) {
|
||||
print(response.body);
|
||||
Map parsedMap = JSON.decode(response.body);
|
||||
token = parsedMap['token'];
|
||||
platform.invokeMethod('saveToken', {'token' : token}).then((value) {
|
||||
print(value.toString());
|
||||
});
|
||||
pushRoute(context, new FinishRegistrationScreen());
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user