Регистрация кассы, авторизация, сканнер готовы к демонстрации
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'main.dart';
|
||||
import 'dart:async';
|
||||
import 'activate_token.dart';
|
||||
|
||||
/// Экран регистрации магазина и кассы.
|
||||
@@ -9,7 +10,7 @@ class RegistrationScreen extends StatefulWidget {
|
||||
@override State createState() => new _RegistrationScreenState();
|
||||
}
|
||||
|
||||
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
class _RegistrationScreenState extends State<RegistrationScreen> {
|
||||
|
||||
String _merchantID = "";
|
||||
bool _loading = false;
|
||||
@@ -20,7 +21,7 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
|
||||
AppBar _getAppBar() {
|
||||
return new AppBar(title: new Text("Регистрация"),
|
||||
actions: <Widget>[new IconButton(icon: new Icon(Icons.help_outline), onPressed: faq)]);
|
||||
actions: <Widget>[new IconButton(icon: new Icon(Icons.help_outline), onPressed: () {})]);
|
||||
}
|
||||
|
||||
Widget _getScreen(BuildContext context) {
|
||||
@@ -70,7 +71,7 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
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, _merchantID) : null,
|
||||
onPressed: _isValidMerchantID() ? () => _registerShop(context) : null,
|
||||
color: primaryColor));
|
||||
}
|
||||
|
||||
@@ -79,57 +80,63 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
}
|
||||
|
||||
_isValidMerchantID() {
|
||||
return _merchantID.length == 5;
|
||||
return merchantID.length == 5;
|
||||
}
|
||||
|
||||
_handleUserInput(String text) {
|
||||
if (text.length > 0) {
|
||||
setState(() {
|
||||
_merchantID = text;
|
||||
merchantID = text;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_registerShop(BuildContext context, String merchantShop) {
|
||||
_registerShop(BuildContext context) {
|
||||
setState(() {
|
||||
loading = true;
|
||||
_register(context, merchantShop);
|
||||
_loading = true;
|
||||
_registerDemo(context);
|
||||
});
|
||||
}
|
||||
|
||||
_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());
|
||||
});
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
_registerDemo(BuildContext context) {
|
||||
new Future.delayed(const Duration(milliseconds: 1000), () {
|
||||
_loading = false;
|
||||
pushRoute(context, new FinishRegistrationScreen());
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
});
|
||||
}
|
||||
|
||||
_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());
|
||||
// });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user