Files
checker/lib/registration.dart

131 lines
4.0 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:async';
import 'main.dart';
/// Экран регистрации магазина и кассы.
class RegistrationScreen extends StatefulWidget {
@override State createState() => new _RegistrationScreenState();
}
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
static const platform = const MethodChannel('com.dinnect.checker');
String _merchantID = "";
String _posNumber = "";
@override Widget build(BuildContext context) {
return new Scaffold(appBar: _getAppBar(), body: _getScreen());
}
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,
)
]);
}
/// На экране будет отображаться Column, с отцентрированными виджетами.
Widget _getScreen() {
return new Center(child: new Column(children: _getChildren()));
}
Future<Null> startScanner() async {
try {
platform.invokeMethod('startScanner');
} on PlatformException {
}
}
List<Widget> _getChildren() {
return<Widget>[
_getLogo(),
_getDecoratedInputField("ID магазина", 0.0),
_getDecoratedInputField("Номер кассы", 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)));
}
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(text) );
}
void _handleUserInput(String text) {
if (text.length > 0) {
setState(() { //new
_merchantID = 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() {
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: _merchantID.length == 0
? null
: () => _register(_merchantID),
disabledColor: const Color(0xffbfbfbf))));
}
void _register(String merchantShop) {
_registerToken(merchantShop);
}
Future<Null> _registerToken(String merchantShop) async {
String pos = await platform.invokeMethod('getInstanceID');
String userAgent = 'dm-checker-test v1.0.1';
var body = {
'merchant_shop' : merchantShop,
'pos' : pos,
'description' : userAgent + '-' + pos
};
httpClient.post(intUrl, body: body).then((response) {
print(response);
}).catchError((error) {
print(error);
});
}
}