import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'main.dart'; import 'dart:async'; import 'activate_token.dart'; /// Экран регистрации магазина и кассы. class RegistrationScreen extends StatefulWidget { @override State createState() => new _RegistrationScreenState(); } class _RegistrationScreenState extends State { String _merchantID = ""; bool _loading = false; @override Widget build(BuildContext context) { return new Scaffold(appBar: _getAppBar(), body: _getScreen(context)); } AppBar _getAppBar() { return new AppBar(title: new Text("Регистрация"), actions: [new IconButton(icon: new Icon(Icons.help_outline), onPressed: () {})]); } Widget _getScreen(BuildContext context) { return new Stack(children: [_getScreenContent(), _getProgressIndicator()]); } Widget _getScreenContent() { return new Container(height: 332.0, child: new ListView(reverse: true, children: [ new Center(child: new Column(children: [ _getLogo(), _getDecoratedInputField(), _getButton(context)])) ].reversed.toList())); } Widget _getProgressIndicator() { return new Center(child: _loading ? new CircularProgressIndicator() : null); } Widget _getLogo() { return new Container(height: 192.0, width: 156.0, child: new Image.asset(logo_png, height: 24.0, width: 156.0)); } Widget _getDecoratedInputField() { 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: _getDecoraionForInputField(), child: _getInputField()); } Widget _getInputField() { return new TextField(decoration: new InputDecoration.collapsed(hintText: merchantIDHint, hintStyle: new TextStyle(color: const Color(0xffa5a5a5), fontSize: 16.0)), onChanged: (text) => _handleUserInput(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))); } Widget _getButton(BuildContext context) { return new Container(margin: new EdgeInsets.only(top: 36.0), height: 42.0, padding: new EdgeInsets.only(left: 40.0, right: 40.0), child: new RaisedButton(child: new Text('ЗАРЕГИСТРИРОВАТЬ', style: new TextStyle(color: Colors.white)), onPressed: _isValidMerchantID() ? () => _registerShop(context) : null, color: primaryColor)); } Widget _getCircularProgressIndicator() { return new Center(child: new CircularProgressIndicator()); } _isValidMerchantID() { return merchantID.length == 5; } _handleUserInput(String text) { if (text.length > 0) { setState(() { merchantID = text; }); } } _registerShop(BuildContext context) { setState(() { _loading = true; _registerDemo(context); }); } _registerDemo(BuildContext context) { new Future.delayed(const Duration(milliseconds: 1000), () { _loading = false; pushRoute(context, new FinishRegistrationScreen()); }); } _register(BuildContext context) 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()); // }); // setState(() { // loading = false; // }); // pushRoute(context, new FinishRegistrationScreen()); // }).catchError((error) { // print(error.toString()); // }); } }