Реализовано получение токена кассы

This commit is contained in:
Ivan Murashov
2017-07-18 09:43:00 +03:00
parent 79a16fb81f
commit fc07eca469
4 changed files with 54 additions and 57 deletions

View File

@@ -3,7 +3,7 @@ import 'package:flutter/services.dart';
import 'splash.dart';
const String _name = 'Ivan Murashov';
const String intUrl = 'https://pos-api.dinect.com/20130701/';
const String intUrl = 'https://pos-api-int.dinect.com/20130701/';
const String intToken = '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';
final httpClient = createHttpClient();
@@ -27,7 +27,4 @@ abstract class BaseState<T> extends State<StatefulWidget> {
void logout() {
}
}
//DMUrl := 'http://pos-api-int.dinect.com/20130701/';
//DMAToken := '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';
}

View File

@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:async';
import 'main.dart';
/// Экран регистрации магазина и кассы.
@@ -10,10 +9,11 @@ class RegistrationScreen extends StatefulWidget {
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
static const platform = const MethodChannel('com.dinnect.checker');
static const String _merchantIDHint = 'ID магазина';
static const String _posIDHint = 'Номер кассы';
String _merchantID = "";
String _posNumber = "";
String _posID = "";
@override Widget build(BuildContext context) {
return new Scaffold(appBar: _getAppBar(), body: _getScreen());
@@ -35,24 +35,15 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
]);
}
/// На экране будет отображаться 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),
_getDecoratedInputField(_merchantIDHint, 0.0),
_getDecoratedInputField(_posIDHint, 36.0),
_getButton()
];
}
@@ -78,13 +69,16 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
return new TextField(decoration: new InputDecoration(hintText: hint,
hideDivider: true,
hintStyle: new TextStyle(color: const Color(0xffa5a5a5),
fontSize: 16.0)), onChanged: (text) => _handleUserInput(text) );
fontSize: 16.0)), onChanged: (text) => _handleUserInput(hint, text));
}
void _handleUserInput(String text) {
void _handleUserInput(String hint, String text) {
if (text.length > 0) {
setState(() { //new
_merchantID = text;
setState(() {
if (hint == _merchantIDHint)
_merchantID = text;
else if (hint == _posIDHint)
_posID = text;
});
}
}
@@ -101,31 +95,41 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
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),
onPressed: _isFieldsAreFilled() ? () => _register(_merchantID) : null,
disabledColor: const Color(0xffbfbfbf))));
}
void _register(String merchantShop) {
_registerToken(merchantShop);
_isFieldsAreFilled() {
print(_merchantID.length);
print(_posID.length);
return _merchantID.length == 5 && _posID.length > 0;
}
Future<Null> _registerToken(String merchantShop) async {
_register(String merchantShop) async {
const platform = const MethodChannel('com.dinnect.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
'merchant_shop': merchantShop,
'pos': pos,
'description': userAgent + '-' + pos
};
httpClient.post(intUrl, body: body).then((response) {
print(response);
print(url);
for (var value in body.values) {
print(value);
}
httpClient.post(url, body: body).then((response) {
print(response.body);
}).catchError((error) {
print(error);
print(error.toString());
});
}
}

View File

@@ -2,7 +2,6 @@ import 'dart:async';
import 'registration.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class SplashScreen extends StatelessWidget {