diff --git a/android/app/src/main/java/com/dinect/checker/activity/MainActivity.java b/android/app/src/main/java/com/dinect/checker/activity/MainActivity.java index 7e1a3c5..18a13cd 100644 --- a/android/app/src/main/java/com/dinect/checker/activity/MainActivity.java +++ b/android/app/src/main/java/com/dinect/checker/activity/MainActivity.java @@ -18,44 +18,41 @@ import com.google.android.gms.iid.InstanceID; public class MainActivity extends FlutterActivity { - private static final String SCANNER_CHANNEL = "com.dinnect.checker"; -// private static final String INSTANCE_ID_CHANNEL = "com.dinnect.checker/instance_id"; - - private String mInstanceID = null; + private static final String INSTANCE_ID_CHANNEL = "com.dinnect.checker/instance_id"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); GeneratedPluginRegistrant.registerWith(this); -// new MethodChannel(getFlutterView(), INSTANCE_ID_CHANNEL).setMethodCallHandler( -// new MethodCallHandler() { -// @Override -// public void onMethodCall(MethodCall call, Result result) { -// -// } -// }); - - new MethodChannel(getFlutterView(), SCANNER_CHANNEL).setMethodCallHandler( + new MethodChannel(getFlutterView(), INSTANCE_ID_CHANNEL).setMethodCallHandler( new MethodCallHandler() { @Override public void onMethodCall(MethodCall call, Result result) { + if (call.method.equals("getInstanceID")) { + InstanceID instanceID = InstanceID.getInstance(MainActivity.this); + String id = instanceID.getId(); + + if (id != null) { + result.success(id); + } else { + result.error("UNAVAILABLE", "Can't get instanceID.", null); + } + + } else { + result.notImplemented(); + } } }); } public void startScanner() { - startActivity(new Intent(MainActivity.this, CameraActivity.class)); + } - public String getInstanceID() { - if (mInstanceID == null) { - InstanceID instanceID = InstanceID.getInstance(this); - mInstanceID = instanceID.getId(); - } - Log.d() - return mInstanceID; + public void getInstanceID() { + } } diff --git a/lib/main.dart b/lib/main.dart index 47cfb26..9d82383 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 extends State { void logout() { } -} - -//DMUrl := 'http://pos-api-int.dinect.com/20130701/'; -//DMAToken := '9fec83cdca38c357e6b65dbb17514cdd36bf2a08'; +} \ No newline at end of file diff --git a/lib/registration.dart b/lib/registration.dart index 6ad74a3..0001a8d 100644 --- a/lib/registration.dart +++ b/lib/registration.dart @@ -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 { - 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 { ]); } - /// На экране будет отображаться Column, с отцентрированными виджетами. Widget _getScreen() { return new Center(child: new Column(children: _getChildren())); } - Future startScanner() async { - try { - platform.invokeMethod('startScanner'); - } on PlatformException { - - } - } - List _getChildren() { return[ _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 { 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 { 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 _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()); }); + } } \ No newline at end of file diff --git a/lib/splash.dart b/lib/splash.dart index 84193b1..2a289a9 100644 --- a/lib/splash.dart +++ b/lib/splash.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'registration.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; class SplashScreen extends StatelessWidget {