139 lines
4.4 KiB
Dart
139 lines
4.4 KiB
Dart
import 'dart:convert';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'main.dart';
|
|
import 'activate_token.dart';
|
|
|
|
/// Экран регистрации магазина и кассы.
|
|
class RegistrationScreen extends StatefulWidget {
|
|
@override State createState() => new _RegistrationScreenState();
|
|
}
|
|
|
|
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
|
|
|
String _merchantID = "";
|
|
String _posID = "";
|
|
|
|
@override Widget build(BuildContext context) {
|
|
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
|
|
}
|
|
|
|
AppBar _getAppBar() {
|
|
return new AppBar(title: new Text("Регистрация магазина"),
|
|
backgroundColor: const Color(0xff4272e7), actions: <Widget>[
|
|
new IconButton(
|
|
icon: new Icon(Icons.help_outline),
|
|
tooltip: 'Air it',
|
|
onPressed: faq,
|
|
),
|
|
new IconButton(
|
|
icon: new Image(height: 24.0, width: 24.0, image: new AssetImage('assets/logout.png')),
|
|
tooltip: 'Restitch it',
|
|
onPressed: logout,
|
|
)
|
|
]);
|
|
}
|
|
|
|
Widget _getScreen(BuildContext context) {
|
|
return new Center(child: new Column(children: <Widget>[
|
|
_getLogo(),
|
|
_getDecoratedInputField(merchantIDHint, 0.0),
|
|
_getDecoratedInputField(posIDHint, 36.0),
|
|
_getButton(context)
|
|
]));
|
|
}
|
|
|
|
|
|
Container _getLogo() {
|
|
return new Container(height: 192.0,
|
|
child: new Image.asset(logo_png, height: 24.0, width: 156.0));
|
|
}
|
|
|
|
Container _getDecoratedInputField(String hint, double topPadding) {
|
|
return new Container(
|
|
padding: new EdgeInsets.only(left: 28.0, right: 28.0, top: topPadding),
|
|
child: new Container(height: 48.0,
|
|
padding: new EdgeInsets.only(left: 16.0, right: 16.0),
|
|
decoration: _getDecoraionForInputField(),
|
|
child: _getInputField(hint))) ;
|
|
}
|
|
|
|
TextField _getInputField(String hint) {
|
|
return new TextField(decoration: new InputDecoration(hintText: hint,
|
|
hideDivider: true,
|
|
hintStyle: new TextStyle(color: const Color(0xffa5a5a5),
|
|
fontSize: 16.0)), onChanged: (text) => _handleUserInput(hint, text));
|
|
}
|
|
|
|
void _handleUserInput(String hint, String text) {
|
|
if (text.length > 0) {
|
|
setState(() {
|
|
if (hint == merchantIDHint)
|
|
_merchantID = text;
|
|
else if (hint == posIDHint)
|
|
_posID = text;
|
|
});
|
|
}
|
|
}
|
|
|
|
Decoration _getDecoraionForInputField() {
|
|
return new BoxDecoration(color: Colors.white,
|
|
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: _isFieldsAreFilled() ? () => _registerShop(context, _merchantID) : null,
|
|
disabledColor: const Color(0xffbfbfbf),
|
|
color: const Color(0xff3078c0))));
|
|
}
|
|
|
|
_isFieldsAreFilled() {
|
|
print(_merchantID.length);
|
|
print(_posID.length);
|
|
return _merchantID.length == 5 && _posID.length > 0;
|
|
}
|
|
|
|
void _registerShop(BuildContext context, String merchantShop) {
|
|
_register(context, merchantShop);
|
|
}
|
|
|
|
_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);
|
|
String userAgent = 'dm-checker-test v1.0.1';
|
|
|
|
var body = {
|
|
'merchant_shop': merchantShop,
|
|
'pos': pos,
|
|
'description': userAgent + '-' + pos
|
|
};
|
|
|
|
print(url);
|
|
|
|
for (var value in body.values) {
|
|
print(value);
|
|
}
|
|
|
|
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());
|
|
});
|
|
|
|
}
|
|
} |