Начал добавлять запросы на регистрацию, валидацию, удаление токена кассы

This commit is contained in:
Ivan Murashov
2017-07-17 19:02:50 +03:00
parent a14f521b1f
commit 79a16fb81f
11 changed files with 163 additions and 52 deletions

View File

@@ -1,7 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'splash.dart';
const String _name = "Ivan Murashov";
const String _name = 'Ivan Murashov';
const String intUrl = 'https://pos-api.dinect.com/20130701/';
const String intToken = '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';
final httpClient = createHttpClient();
void main() {
runApp(new Checker());
@@ -23,3 +28,6 @@ abstract class BaseState<T> extends State<StatefulWidget> {
}
}
//DMUrl := 'http://pos-api-int.dinect.com/20130701/';
//DMAToken := '9fec83cdca38c357e6b65dbb17514cdd36bf2a08';

View File

@@ -10,14 +10,15 @@ class RegistrationScreen extends StatefulWidget {
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
static const platform = const MethodChannel('com.dinnect.checker/scanner');
static const platform = const MethodChannel('com.dinnect.checker');
String _merchantID = "";
String _posNumber = "";
@override Widget build(BuildContext context) {
return new Scaffold(appBar: _getAppBar(), body: _getScreen());
}
faq() {}
AppBar _getAppBar() {
return new AppBar(title: new Text("Регистрация магазина"),
backgroundColor: const Color(0xff4272e7), actions: <Widget>[
@@ -77,7 +78,15 @@ 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)));
fontSize: 16.0)), onChanged: (text) => _handleUserInput(text) );
}
void _handleUserInput(String text) {
if (text.length > 0) {
setState(() { //new
_merchantID = text;
});
}
}
Decoration _getDecoraionForInputField() {
@@ -92,9 +101,31 @@ 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: null, disabledColor: const Color(0xffbfbfbf))));
onPressed: _merchantID.length == 0
? null
: () => _register(_merchantID),
disabledColor: const Color(0xffbfbfbf))));
}
doStuff() {}
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);
});
}
}

View File

@@ -2,21 +2,24 @@ import 'dart:async';
import 'registration.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class SplashScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
new Future.delayed(const Duration(milliseconds: 1000), () {
_goToNextScreen(context);
});
return new Image.asset('assets/splash.png', fit: BoxFit.cover);
}
_goToNextScreen(BuildContext context) {
_goToNextScreen(BuildContext context) async {
Navigator.of(context).push(new MaterialPageRoute<Null>(
builder: (BuildContext context) {
return new RegistrationScreen();
}));
builder: (BuildContext context) {
return new RegistrationScreen();
}));
}
}