Регистрация, проверка токена, обработка ошибок, сканирование
This commit is contained in:
@@ -2,6 +2,7 @@ package com.dinect.checker.activity;
|
|||||||
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -69,7 +70,7 @@ public class CameraActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.setTitle(getString(R.string.scanner_title));
|
actionBar.setTitle(getString(R.string.scanner_title));
|
||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
mCamera = getCameraInstance();
|
mCamera = getCameraInstance();
|
||||||
@@ -117,6 +118,12 @@ public class CameraActivity extends AppCompatActivity {
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
setResult(RESULT_CANCELED);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
@@ -193,6 +200,10 @@ public class CameraActivity extends AppCompatActivity {
|
|||||||
SymbolSet syms = mScanner.getResults();
|
SymbolSet syms = mScanner.getResults();
|
||||||
for (Symbol sym : syms) {
|
for (Symbol sym : syms) {
|
||||||
mBarcodeScanned = true;
|
mBarcodeScanned = true;
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.putExtra("code", sym.getData());
|
||||||
|
setResult(RESULT_OK, intent);
|
||||||
|
finish();
|
||||||
Toast.makeText(CameraActivity.this, sym.getData(), Toast.LENGTH_SHORT).show();
|
Toast.makeText(CameraActivity.this, sym.getData(), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,11 @@ import java.util.Map;
|
|||||||
public class MainActivity extends FlutterActivity {
|
public class MainActivity extends FlutterActivity {
|
||||||
|
|
||||||
private static final int START_SCANNER_REQUEST_CODE = 2017;
|
private static final int START_SCANNER_REQUEST_CODE = 2017;
|
||||||
|
private static final String PREF_POS_TOKEN = "pref_pos_token";
|
||||||
|
private static final String PREF_POS_MERCHANT_ID = "pref_pos_merchant_id";
|
||||||
|
|
||||||
private MethodChannel mChannel;
|
private MethodChannel mChannel;
|
||||||
|
private SharedPreferences mPreferences;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -28,8 +31,7 @@ public class MainActivity extends FlutterActivity {
|
|||||||
GeneratedPluginRegistrant.registerWith(this);
|
GeneratedPluginRegistrant.registerWith(this);
|
||||||
|
|
||||||
final String INSTANCE_ID_CHANNEL = "com.dinect.checker/instance_id";
|
final String INSTANCE_ID_CHANNEL = "com.dinect.checker/instance_id";
|
||||||
final String PREF_POS_TOKEN = "pref_pos_token";
|
mPreferences = getPreferences(Context.MODE_PRIVATE);
|
||||||
final SharedPreferences preferences = getPreferences(Context.MODE_PRIVATE);
|
|
||||||
|
|
||||||
mChannel = new MethodChannel(getFlutterView(), INSTANCE_ID_CHANNEL);
|
mChannel = new MethodChannel(getFlutterView(), INSTANCE_ID_CHANNEL);
|
||||||
mChannel.setMethodCallHandler(
|
mChannel.setMethodCallHandler(
|
||||||
@@ -47,13 +49,18 @@ public class MainActivity extends FlutterActivity {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "saveToken":
|
case "saveToken":
|
||||||
Map arguments = call.arguments();
|
Map tokenArguments = call.arguments();
|
||||||
String token = (String) arguments.get("token");
|
mPreferences.edit().putString(PREF_POS_TOKEN, (String) tokenArguments.get("token")).apply();
|
||||||
Log.d("kifio", token);
|
|
||||||
preferences.edit().putString(PREF_POS_TOKEN, token).apply();
|
|
||||||
break;
|
break;
|
||||||
case "getToken":
|
case "getToken":
|
||||||
result.success(preferences.getString(PREF_POS_TOKEN, null));
|
result.success(mPreferences.getString(PREF_POS_TOKEN, null));
|
||||||
|
break;
|
||||||
|
case "saveMerchantID":
|
||||||
|
Map merchantIDArguments = call.arguments();
|
||||||
|
mPreferences.edit().putString(PREF_POS_MERCHANT_ID, (String) merchantIDArguments.get("merchantID")).apply();
|
||||||
|
break;
|
||||||
|
case "getMerchantID":
|
||||||
|
result.success(mPreferences.getString(PREF_POS_MERCHANT_ID, null));
|
||||||
break;
|
break;
|
||||||
case "startScanner":
|
case "startScanner":
|
||||||
Intent cameraIntent = new Intent(MainActivity.this, CameraActivity.class);
|
Intent cameraIntent = new Intent(MainActivity.this, CameraActivity.class);
|
||||||
@@ -69,11 +76,28 @@ public class MainActivity extends FlutterActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == START_SCANNER_REQUEST_CODE && resultCode == RESULT_OK) {
|
if (requestCode == START_SCANNER_REQUEST_CODE && resultCode == RESULT_CANCELED) {
|
||||||
mChannel.invokeMethod("foo", null);
|
finish();
|
||||||
|
} else if (requestCode == START_SCANNER_REQUEST_CODE && resultCode == RESULT_OK) {
|
||||||
|
if (data == null) {
|
||||||
|
logout();
|
||||||
|
} else {
|
||||||
|
String code = data.getExtras().getString("code", null);
|
||||||
|
if (code == null) {
|
||||||
|
logout();
|
||||||
|
} else {
|
||||||
|
mChannel.invokeMethod("purchase", code);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void logout() {
|
||||||
|
mChannel.invokeMethod("foo", null);
|
||||||
|
mPreferences.edit().remove(PREF_POS_TOKEN).apply();
|
||||||
|
mPreferences.edit().remove(PREF_POS_MERCHANT_ID).apply();
|
||||||
|
}
|
||||||
|
|
||||||
public void startScanner() {
|
public void startScanner() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -90,4 +114,12 @@ public class MainActivity extends FlutterActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveMerchantID() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getMerchantID() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,39 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
<LinearLayout android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="?attr/actionBarSize">
|
||||||
|
|
||||||
|
<View android:layout_height="0dp"
|
||||||
|
android:layout_weight="0.42"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:background="#с0000000"/>
|
||||||
|
|
||||||
|
<FrameLayout android:layout_height="0dp"
|
||||||
|
android:layout_weight="0.16"
|
||||||
|
android:layout_width="match_parent">
|
||||||
|
|
||||||
|
<View android:layout_height="match_parent"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_gravity="left"
|
||||||
|
android:background="#с0000000"/>
|
||||||
|
|
||||||
|
<View android:layout_height="match_parent"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_gravity="right"
|
||||||
|
android:background="#с0000000"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<View android:layout_height="0dp"
|
||||||
|
android:layout_weight="0.42"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:background="#с0000000"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
<android.support.v7.widget.Toolbar
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
BIN
assets/active_token_message_background.png
Normal file
BIN
assets/active_token_message_background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
@@ -1,20 +1,25 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'main.dart';
|
import 'main.dart';
|
||||||
|
import 'dart:convert'; // Пакет для обработки json с ответом от сервера.
|
||||||
|
|
||||||
|
/// TODO: Вот это все ерунда конечно, это должно обрабатыватсья через state экрана регистрации.
|
||||||
|
|
||||||
/// Экран регистрации магазина и кассы.
|
|
||||||
class FinishRegistrationScreen extends StatefulWidget {
|
class FinishRegistrationScreen extends StatefulWidget {
|
||||||
@override State createState() => new _RegistrationScreenState();
|
@override State createState() => new _RegistrationScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _RegistrationScreenState extends State<FinishRegistrationScreen> {
|
class _RegistrationScreenState extends State<FinishRegistrationScreen> {
|
||||||
|
|
||||||
|
bool _tokenActive = false;
|
||||||
|
String _merchantID = null;
|
||||||
|
|
||||||
@override Widget build(BuildContext context) {
|
@override Widget build(BuildContext context) {
|
||||||
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
|
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
AppBar _getAppBar() {
|
AppBar _getAppBar() {
|
||||||
return new AppBar(title: new Text("Регистрация магазина"),
|
return new AppBar(title: new Text("Регистрация", style: new TextStyle(fontSize: 18.0)),
|
||||||
backgroundColor: primaryColor, actions: <Widget>[
|
backgroundColor: primaryColor, actions: <Widget>[
|
||||||
new IconButton(
|
new IconButton(
|
||||||
icon: new Icon(Icons.help_outline),
|
icon: new Icon(Icons.help_outline),
|
||||||
@@ -23,67 +28,97 @@ class _RegistrationScreenState extends State<FinishRegistrationScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _getScreen(BuildContext context) {
|
Widget _getScreen(BuildContext context) {
|
||||||
return new Center(child: new Column(children: <Widget>[
|
if (_merchantID == null) {
|
||||||
|
_getSavedMerchantID();
|
||||||
|
}
|
||||||
|
return new Column(children: <Widget>[
|
||||||
_getLogo(),
|
_getLogo(),
|
||||||
|
_getMerchantIDTitle(),
|
||||||
_getDecoratedText(),
|
_getDecoratedText(),
|
||||||
_getMessage(),
|
_getMessage(),
|
||||||
_getButton(context)
|
_getButton(context)
|
||||||
]));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Container _getLogo() {
|
_getLogo() {
|
||||||
return new Container(padding: new EdgeInsets.only(top: 16.0, bottom: 16.0),
|
double containerHeight = 92.0;
|
||||||
child: new Image.asset(logo_png, height: 24.0, width: 156.0));
|
double imageWidth = 156.0;
|
||||||
|
return new Container(height: containerHeight, child: new Image.asset(logo_png, width: imageWidth));
|
||||||
}
|
}
|
||||||
|
|
||||||
Container _getDecoratedText() {
|
_getMerchantIDTitle() {
|
||||||
|
return new Container(margin: new EdgeInsets.only(top: 8.0, bottom: 8.0, left: 28.0, right: 28.0),
|
||||||
|
child: new Row(crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: <Widget>[new Text('ID Магазина', textAlign: TextAlign.left, style: new TextStyle(fontWeight: FontWeight.w300, color: greyTextColor, fontSize: 14.0))]));
|
||||||
|
}
|
||||||
|
|
||||||
|
_getDecoratedText() {
|
||||||
return new Container(margin: new EdgeInsets.only(left: 28.0, right: 28.0),
|
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),
|
padding: new EdgeInsets.only(top: 12.0, bottom: 12.0, left: 16.0, right: 16.0),
|
||||||
decoration: _getDecoraionForMerchantId(),
|
decoration: _getDecoraionForMerchantId(),
|
||||||
child: _getMerchantIDText());
|
child: new Row(children: <Widget>[_getMerchantIDText()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
Text _getMerchantIDText() {
|
_getMerchantIDText() {
|
||||||
return new Text(merchantID, style: new TextStyle(color: const Color(0xffa5a5a5), fontSize: 16.0));
|
return new Text(_merchantID != null ? _merchantID : '', style: new TextStyle(color: Colors.black, fontSize: 16.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
_getSavedMerchantID() {
|
||||||
|
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
||||||
|
platform.invokeMethod('getMerchantID').then((result) {
|
||||||
|
setState(() {
|
||||||
|
_merchantID = result;
|
||||||
|
print(_merchantID);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Container _getMessage() {
|
Container _getMessage() {
|
||||||
return new Container(padding: new EdgeInsets.only(top: 20.0, left: 26.0, right: 26.0),
|
return new Container(height: _tokenActive ? 72.0 : 108.0, decoration: _getDecoraionForMessageField(),
|
||||||
child: new Container(height: 128.0, decoration: _getDecoraionForMessageField(),
|
margin: new EdgeInsets.only(top: 20.0, left: 12.0, right: 12.0),
|
||||||
padding: new EdgeInsets.only(top: 16.0, bottom: 8.0, left: 28.0, right: 28.0),
|
padding: new EdgeInsets.only(bottom: 16.0, left: 14.0, right: 14.0),
|
||||||
child: new Text('Запрос на активацию программы отправлен, дождrитесь подтверждения активации администратором',
|
child: new Center(child: new Text(_tokenActive ? 'Программа активирована' : 'Запрос на активацию программы отправлен, дождитесь подтверждения активации администратором',
|
||||||
textAlign: TextAlign.center, style: new TextStyle(fontWeight: FontWeight.bold, color: const Color(0xff4e3a19)))));
|
textAlign: TextAlign.center, style: new TextStyle(height: 1.5, fontWeight: FontWeight.bold, fontSize: 14.0, color: _tokenActive ? tokenActiveTextColor : tokenActivateTextColor))));
|
||||||
}
|
}
|
||||||
|
|
||||||
Decoration _getDecoraionForMessageField() {
|
Decoration _getDecoraionForMessageField() {
|
||||||
return new BoxDecoration(image: new DecorationImage(
|
return new BoxDecoration(image: new DecorationImage(
|
||||||
image: new ExactAssetImage(activate_token_bg_png), fit: BoxFit.fill));
|
image: new ExactAssetImage(_tokenActive ? active_token_bg_png : activate_token_bg_png), fit: _tokenActive ? BoxFit.fitWidth : BoxFit.fill));
|
||||||
}
|
}
|
||||||
|
|
||||||
Decoration _getDecoraionForMerchantId() {
|
Decoration _getDecoraionForMerchantId() {
|
||||||
return new BoxDecoration(color: Colors.white,
|
return new BoxDecoration(color: textFieldBackground,
|
||||||
border: new Border.all(color: const Color(0xffcfd8dc), width: 1.0),
|
border: new Border.all(color: const Color(0xffcfd8dc), width: 1.0),
|
||||||
borderRadius: new BorderRadius.all(new Radius.circular(4.0)));
|
borderRadius: new BorderRadius.all(new Radius.circular(4.0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Container _getButton(BuildContext context) {
|
/// Метод возвращает кнопку, которая запускает отправку токена кассы на сервер.
|
||||||
return new Container(padding: new EdgeInsets.only(top: 36.0),
|
_getButton(BuildContext context) {
|
||||||
child: new Container(height: 64.0, padding: new EdgeInsets.all(8.0),
|
double buttonHeight = 42.0;
|
||||||
child: new RaisedButton(child: new Text('Обновить статус активации',
|
double topMargin = 8.0;
|
||||||
style: new TextStyle(color: Colors.white)),
|
return new Container(margin: new EdgeInsets.only(top: topMargin), height: buttonHeight,
|
||||||
onPressed: () {
|
child: new RaisedButton(child: new Text(_tokenActive ? 'ЗАВЕРШИТЬ РЕГИСТРАЦИЮ' : 'ОБНОВИТЬ СТАТУС АКТИВАЦИИ',
|
||||||
startScanner(context);
|
style: new TextStyle(fontSize: 14.0, color: Colors.white)),
|
||||||
})));
|
onPressed: () {
|
||||||
|
if (_tokenActive) {
|
||||||
|
startScanner(context);
|
||||||
|
} else {
|
||||||
|
checkToken(context).then((response) {
|
||||||
|
|
||||||
|
print(response.body);
|
||||||
|
Map parsedMap = JSON.decode(response.body);
|
||||||
|
|
||||||
|
// Обновить экран, заменить сообщение о необходимости активации токена, на сообщние о том, что токен активен.
|
||||||
|
setState(() {
|
||||||
|
_tokenActive = parsedMap['active'];
|
||||||
|
});
|
||||||
|
|
||||||
|
}).catchError((error) {
|
||||||
|
print(error.toString());
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
color: primaryColor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_checkToken(BuildContext context) {
|
|
||||||
checkToken(context, new CheckTokenCallback());
|
|
||||||
}
|
|
||||||
|
|
||||||
class CheckTokenCallback extends Callback {
|
|
||||||
|
|
||||||
call(BuildContext context) {
|
|
||||||
startScanner();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,7 @@ import 'splash.dart';
|
|||||||
import 'registration.dart';
|
import 'registration.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'purchase.dart';
|
||||||
|
|
||||||
/// Главный класс приложения.
|
/// Главный класс приложения.
|
||||||
/// Здесь распоосложены константы и некоторые методы, которые могут вызываться с разных экранов приложения.
|
/// Здесь распоосложены константы и некоторые методы, которые могут вызываться с разных экранов приложения.
|
||||||
@@ -21,56 +22,62 @@ const String logo_png = 'assets/registration_logo.png';
|
|||||||
const String splash_png = 'assets/splash.png';
|
const String splash_png = 'assets/splash.png';
|
||||||
const String logout_png = 'assets/logout.png';
|
const String logout_png = 'assets/logout.png';
|
||||||
const String activate_token_bg_png = 'assets/activate_token_message_background.png';
|
const String activate_token_bg_png = 'assets/activate_token_message_background.png';
|
||||||
|
const String active_token_bg_png = 'assets/active_token_message_background.png';
|
||||||
|
|
||||||
// Colors
|
// Colors
|
||||||
const Color primaryColor = const Color(0xffeb0004);
|
const Color primaryColor = const Color(0xffeb0004);
|
||||||
const Color disabledColor = const Color(0xffbfbfbf);
|
const Color greyTextColor = const Color(0xffa5a5a5);
|
||||||
|
const Color textBorderColor = const Color(0xffcfd8dc);
|
||||||
|
const Color textFieldBackground = const Color(0xffefefef);
|
||||||
|
const Color tokenActiveTextColor = const Color(0xff1f5a1f);
|
||||||
|
const Color tokenActivateTextColor = const Color(0xff4e3a19);
|
||||||
|
|
||||||
// HttpClient
|
// HttpClient
|
||||||
final httpClient = createHttpClient();
|
final httpClient = createHttpClient();
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(new Checker());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Токен кассы. Инициализируется при регистрации.
|
/// Токен кассы. Инициализируется при регистрации.
|
||||||
String token;
|
String token;
|
||||||
String merchantID = "";
|
String merchantID = "";
|
||||||
|
|
||||||
|
/// Точка входа в приложение.
|
||||||
|
void main() {
|
||||||
|
runApp(new Checker());
|
||||||
|
}
|
||||||
|
|
||||||
/// Проверка статуса токена. Токен может быть активирован, либо не активирован.
|
/// Проверка статуса токена. Токен может быть активирован, либо не активирован.
|
||||||
void checkToken(BuildContext context, Callback callback) {
|
checkToken(BuildContext context) async {
|
||||||
|
return httpClient.get(intUrl + 'tokens/' + token + '?_dmapptoken=' + intToken);
|
||||||
String url = intUrl + 'tokens/' + token + '?_dmapptoken=' + intToken;
|
|
||||||
print(url);
|
|
||||||
|
|
||||||
httpClient.get(url).then((response) {
|
|
||||||
|
|
||||||
print(response.body);
|
|
||||||
Map parsedMap = JSON.decode(response.body);
|
|
||||||
bool active = parsedMap['active'];
|
|
||||||
|
|
||||||
if (!active) {
|
|
||||||
callback.call(context);
|
|
||||||
} else {
|
|
||||||
// Запускается экран сканера, токен кассы активирован, с его помощью можно делать запросы к pos-api.
|
|
||||||
startScanner(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
}).catchError((error) {
|
|
||||||
print(error.toString());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Запуск спецефичной для каждой платформы части приложения - сканера.
|
/// Запуск спецефичной для каждой платформы части приложения - сканера.
|
||||||
/// Может производиться с нескольких экранов (splash, finish_registration).
|
/// Может производиться с нескольких экранов (splash, finish_registration).
|
||||||
startScanner(BuildContext context) async{
|
startScanner(BuildContext context) async {
|
||||||
|
|
||||||
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
||||||
|
|
||||||
|
// Канал слушает ловит вызовы методов из "нативной" части приложения.
|
||||||
|
// Могут быть вызваны либо logaut либо faq, либо purchase.
|
||||||
platform.setMethodCallHandler((MethodCall call) async {
|
platform.setMethodCallHandler((MethodCall call) async {
|
||||||
pushRoute(context, new RegistrationScreen());
|
|
||||||
return result;
|
if (call.method == 'foo') {
|
||||||
// or
|
|
||||||
// throw new PlatformException(errorCode, anErrorMessage, someDetails);
|
String url = intUrl + 'tokens/' + token + '?_dmapptoken=' + intToken;
|
||||||
|
|
||||||
|
httpClient.delete(url).then((response) {
|
||||||
|
|
||||||
|
print(response.body);
|
||||||
|
|
||||||
|
}).catchError((error) {
|
||||||
|
print(error.toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
pushRoute(context, new RegistrationScreen());
|
||||||
|
} else {
|
||||||
|
pushRoute(context, new PurchaseScreen());
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await platform.invokeMethod('startScanner');
|
await platform.invokeMethod('startScanner');
|
||||||
@@ -87,15 +94,11 @@ pushRoute(BuildContext context, Widget widget) {
|
|||||||
|
|
||||||
class Checker extends StatelessWidget {
|
class Checker extends StatelessWidget {
|
||||||
@override Widget build(BuildContext context) {
|
@override Widget build(BuildContext context) {
|
||||||
return new MaterialApp(title: "DemoApp",
|
return new MaterialApp(title: "AutoClub",
|
||||||
home: new SplashScreen(),
|
home: new SplashScreen(),
|
||||||
theme: new ThemeData(
|
theme: new ThemeData(
|
||||||
primaryColor: primaryColor,
|
primaryColor: primaryColor,
|
||||||
accentColor: primaryColor
|
accentColor: primaryColor
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Callback {
|
|
||||||
void call(BuildContext context);
|
|
||||||
}
|
|
||||||
101
lib/purchase.dart
Normal file
101
lib/purchase.dart
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'main.dart';
|
||||||
|
import 'dart:async';
|
||||||
|
import 'activate_token.dart';
|
||||||
|
|
||||||
|
/// Экран проведения покупки.
|
||||||
|
class PurchaseScreen extends StatefulWidget {
|
||||||
|
@override State createState() => new _PurchaseScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PurchaseScreenState extends State<PurchaseScreen> {
|
||||||
|
|
||||||
|
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: <Widget>[new IconButton(icon: new Icon(Icons.help_outline), onPressed: () {})]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _getScreen(BuildContext context) {
|
||||||
|
return new Stack(children: <Widget>[_getScreenContent(), _getProgressIndicator()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _getScreenContent() {
|
||||||
|
return new Container(height: 332.0,
|
||||||
|
child: new ListView(reverse: true, children: <Widget>[
|
||||||
|
new Column(children: <Widget>[
|
||||||
|
_getValueWithTitle('ФИО', 'Знаменитый Рокер Паук'),
|
||||||
|
_getValueWithTitle('Карта', 'B0399900702'),
|
||||||
|
_getValueWithTitle('Вознаграждение', '100%'),
|
||||||
|
_getButton(context),
|
||||||
|
_getButton(context)])
|
||||||
|
].reversed.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _getProgressIndicator() {
|
||||||
|
return new Center(child: _loading ? new CircularProgressIndicator() : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _getValueWithTitle(String title, String value) {
|
||||||
|
return new Column(children: <Widget>[
|
||||||
|
new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[new Text(title, textAlign: TextAlign.left, style: new TextStyle(color: greyTextColor, fontSize: 14.0))]),
|
||||||
|
new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[new Text(value, textAlign: TextAlign.left, style: new TextStyle(color: Colors.black, fontSize: 20.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: null,
|
||||||
|
color: primaryColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _getCircularProgressIndicator() {
|
||||||
|
return new Center(child: new CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
|
||||||
|
_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());
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert'; // Пакет для обработки json с ответом от сервера.
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'main.dart';
|
import 'main.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'activate_token.dart';
|
import 'activate_token.dart';
|
||||||
|
|
||||||
|
/// На фото мой сын, большой любитель голых констант.
|
||||||
|
|
||||||
/// Экран регистрации магазина и кассы.
|
/// Экран регистрации магазина и кассы.
|
||||||
class RegistrationScreen extends StatefulWidget {
|
class RegistrationScreen extends StatefulWidget {
|
||||||
@override State createState() => new _RegistrationScreenState();
|
@override State createState() => new _RegistrationScreenState();
|
||||||
@@ -12,92 +14,125 @@ class RegistrationScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _RegistrationScreenState extends State<RegistrationScreen> {
|
class _RegistrationScreenState extends State<RegistrationScreen> {
|
||||||
|
|
||||||
String _merchantID = "";
|
String error = null;
|
||||||
bool _loading = false;
|
bool _loading = false;
|
||||||
|
|
||||||
@override Widget build(BuildContext context) {
|
@override build(BuildContext context) {
|
||||||
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
|
return new Scaffold(appBar: _getAppBar(), body: _getScreen(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
AppBar _getAppBar() {
|
_getAppBar() {
|
||||||
return new AppBar(title: new Text("Регистрация"),
|
return new AppBar(title: new Text("Регистрация"),
|
||||||
actions: <Widget>[new IconButton(icon: new Icon(Icons.help_outline), onPressed: () {})]);
|
actions: <Widget>[new IconButton(icon: new Icon(Icons.help_outline), onPressed: () {})]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _getScreen(BuildContext context) {
|
_getScreen(BuildContext context) {
|
||||||
return new Stack(children: <Widget>[_getScreenContent(), _getProgressIndicator()]);
|
return new Stack(children: <Widget>[_getScreenContent(), _getProgressIndicator()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _getScreenContent() {
|
/// Высота контейнера задана для того, чтобы элементы располагались вверху экрана
|
||||||
|
/// и список скроллился снизу вверх при открытии клавиатуры.
|
||||||
|
_getScreenContent() {
|
||||||
return new Container(height: 332.0,
|
return new Container(height: 332.0,
|
||||||
child: new ListView(reverse: true, children: <Widget>[
|
child: new ListView(reverse: true, children: <Widget>[
|
||||||
new Center(child: new Column(children: <Widget>[
|
new Center(child: new Column(children: <Widget>[
|
||||||
_getLogo(),
|
_getLogo(),
|
||||||
_getDecoratedInputField(),
|
_getMerchantIDTitle(),
|
||||||
_getButton(context)]))
|
_getDecoratedInputField(),
|
||||||
].reversed.toList()));
|
_getButton(context)]))
|
||||||
|
].reversed.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _getProgressIndicator() {
|
/// Индикация отправки токена кассы.
|
||||||
|
_getProgressIndicator() {
|
||||||
return new Center(child: _loading ? new CircularProgressIndicator() : null);
|
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));
|
_getLogo() {
|
||||||
|
double containerHeight = 162.0;
|
||||||
|
double imageHeight = 24.0;
|
||||||
|
double imageWidth = 156.0;
|
||||||
|
return new Container(height: containerHeight, child: new Image.asset(logo_png, height: imageHeight, width: imageWidth));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _getDecoratedInputField() {
|
_getMerchantIDTitle() {
|
||||||
return new Container(margin: new EdgeInsets.only(left: 28.0, right: 28.0),
|
return new Container(margin: new EdgeInsets.only(top: 8.0, bottom: 8.0, left: 28.0, right: 28.0),
|
||||||
padding: new EdgeInsets.only(top: 12.0, bottom: 12.0, left: 16.0, right: 16.0),
|
child: new Row(crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
decoration: _getDecoraionForInputField(),
|
children: <Widget>[new Container(padding: new EdgeInsets.only(right: 8.0), child: new Text(_getMerchantIDTitleText(), overflow: TextOverflow.ellipsis, textAlign: TextAlign.left,
|
||||||
child: _getInputField());
|
style: new TextStyle(fontWeight: FontWeight.w300, color: error == null ? greyTextColor : primaryColor, fontSize: 14.0)))]));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _getInputField() {
|
_getMerchantIDTitleText() {
|
||||||
return new TextField(decoration: new InputDecoration.collapsed(hintText: merchantIDHint,
|
if (merchantID.length == 0 && error == null) {
|
||||||
hintStyle: new TextStyle(color: const Color(0xffa5a5a5), fontSize: 16.0)),
|
return ' ';
|
||||||
onChanged: (text) => _handleUserInput(text));
|
} else if (error != null) {
|
||||||
}
|
return error;
|
||||||
|
} else {
|
||||||
Decoration _getDecoraionForInputField() {
|
return 'ID Магазина';
|
||||||
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) {
|
/// Метод возвращает контейнер с установленными отступами, в котором размещен TextField обернутый в BoxDecoration.
|
||||||
|
_getDecoratedInputField() {
|
||||||
|
double margin = 28.0;
|
||||||
|
double verticalPadding = 12.0;
|
||||||
|
double horizontalPadding = 16.0;
|
||||||
|
return new Container(margin: new EdgeInsets.only(left: margin, right: margin),
|
||||||
|
padding: new EdgeInsets.only(top: verticalPadding, bottom: verticalPadding, left: horizontalPadding, right: horizontalPadding),
|
||||||
|
decoration: _getDecoraionForInputField(),
|
||||||
|
child: _getInputField());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Метод возвращает TextField для _getDecoratedInputField
|
||||||
|
_getInputField() {
|
||||||
|
return new TextField(keyboardType: TextInputType.number, decoration: new InputDecoration.collapsed(hintText: merchantIDHint,
|
||||||
|
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
|
||||||
|
onChanged: (text) => _handleUserInput(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Метод возвращает BoxDecoration для _getDecoratedInputField
|
||||||
|
_getDecoraionForInputField() {
|
||||||
|
return new BoxDecoration(color: textFieldBackground,
|
||||||
|
border: new Border.all(color: textBorderColor, width: 1.0,),
|
||||||
|
borderRadius: new BorderRadius.all(new Radius.circular(4.0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Метод возвращает кнопку, которая запускает отправку токена кассы на сервер.
|
||||||
|
_getButton(BuildContext context) {
|
||||||
|
double buttonHeight = 42.0;
|
||||||
|
double topMargin = 36.0;
|
||||||
|
double horizontalPadding = 40.0; // Отступы по краям от кнопки.
|
||||||
|
return new Container(margin: new EdgeInsets.only(top: topMargin), height: buttonHeight,
|
||||||
|
padding: new EdgeInsets.only(left: horizontalPadding, right: horizontalPadding),
|
||||||
|
child: new RaisedButton(child: new Text('ЗАРЕГИСТРИРОВАТЬ',
|
||||||
|
style: new TextStyle(color: Colors.white)),
|
||||||
|
onPressed: _isValidMerchantID() && !_loading ? () => _registerShop(context) : null,
|
||||||
|
color: primaryColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Токен кассы - это DIN код. DIN код - это специальный код динекта, максимальная его длина - 25 символов.
|
||||||
|
_isValidMerchantID() {
|
||||||
|
return merchantID.length > 0 && merchantID.length < 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Смена состояния экрана при изменении текста в поле ввода.
|
||||||
|
_handleUserInput(String text) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_loading = true;
|
merchantID = text;
|
||||||
_registerDemo(context);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Показать индикатор, запросить токен.
|
||||||
|
_registerShop(BuildContext context) {
|
||||||
|
setState(() {
|
||||||
|
_loading = true;
|
||||||
|
_register(context);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Экран зависает на 1 сек, после этого выполняется переход на экран потверждения токена.
|
||||||
_registerDemo(BuildContext context) {
|
_registerDemo(BuildContext context) {
|
||||||
new Future.delayed(const Duration(milliseconds: 1000), () {
|
new Future.delayed(const Duration(milliseconds: 1000), () {
|
||||||
_loading = false;
|
_loading = false;
|
||||||
@@ -105,38 +140,44 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Получение от платформы id установки, формирование запроса на получение токена, сохранение токена.
|
||||||
_register(BuildContext context) async {
|
_register(BuildContext context) async {
|
||||||
// const platform = const MethodChannel('com.dinect.checker/instance_id');
|
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 = {
|
String url = intUrl + 'tokens/?_dmapptoken=' + intToken;
|
||||||
// 'merchant_shop': merchantShop,
|
String pos = (new DateTime.now().millisecondsSinceEpoch / 1000).toString();
|
||||||
// 'pos': pos,
|
|
||||||
// 'description': userAgent + '-' + pos
|
|
||||||
// };
|
|
||||||
|
|
||||||
// print(url);
|
// Поле description - необязательное.
|
||||||
|
var body = {
|
||||||
|
'merchant_shop': merchantID,
|
||||||
|
'pos': pos,
|
||||||
|
};
|
||||||
|
|
||||||
// for (var value in body.values) {
|
httpClient.post(url, body: body).then((response) {
|
||||||
// print(value);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// httpClient.post(url, body: body).then((response) {
|
setState(() {
|
||||||
// print(response.body);
|
error = null;
|
||||||
// Map parsedMap = JSON.decode(response.body);
|
});
|
||||||
// token = parsedMap['token'];
|
|
||||||
// platform.invokeMethod('saveToken', {'token' : token}).then((value) {
|
print(response.body);
|
||||||
// print(value.toString());
|
Map parsedMap = JSON.decode(response.body);
|
||||||
// });
|
setState(() {
|
||||||
// setState(() {
|
_loading = false;
|
||||||
// loading = false;
|
});
|
||||||
// });
|
if (response.statusCode == 201) {
|
||||||
// pushRoute(context, new FinishRegistrationScreen());
|
token = parsedMap['token'];
|
||||||
// }).catchError((error) {
|
platform.invokeMethod('saveToken', {'token' : token});
|
||||||
// print(error.toString());
|
platform.invokeMethod('saveMerchantID', {'merchantID' : merchantID});
|
||||||
// });
|
pushRoute(context, new FinishRegistrationScreen());
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
error = parsedMap['errors'][0];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catchError((error) {
|
||||||
|
setState(() {
|
||||||
|
error = 'Отсутствует интернет соединение';
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
import 'main.dart';
|
import 'main.dart';
|
||||||
import 'registration.dart';
|
import 'registration.dart';
|
||||||
import 'activate_token.dart';
|
import 'activate_token.dart';
|
||||||
import 'dart:async';
|
|
||||||
|
|
||||||
class SplashScreen extends StatelessWidget {
|
class SplashScreen extends StatelessWidget {
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@ class SplashScreen extends StatelessWidget {
|
|||||||
|
|
||||||
// Splash скрин зависает мимнимум на 1 секунду.
|
// Splash скрин зависает мимнимум на 1 секунду.
|
||||||
// После этого начинается проверка токена.
|
// После этого начинается проверка токена.
|
||||||
|
|
||||||
new Future.delayed(const Duration(milliseconds: 1000), () {
|
new Future.delayed(const Duration(milliseconds: 1000), () {
|
||||||
_showNextScreen(context);
|
_showNextScreen(context);
|
||||||
});
|
});
|
||||||
@@ -24,25 +26,35 @@ class SplashScreen extends StatelessWidget {
|
|||||||
|
|
||||||
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
||||||
token = await platform.invokeMethod('getToken');
|
token = await platform.invokeMethod('getToken');
|
||||||
|
print('token: $token');
|
||||||
// В случае, если в приложении отсутствует токен,
|
// В случае, если в приложении отсутствует токен,
|
||||||
// необходимо запустить регистрацию кассы.
|
// необходимо запустить регистрацию кассы.
|
||||||
// if (token == null) {
|
|
||||||
|
if (token == null) {
|
||||||
pushRoute(context, new RegistrationScreen());
|
pushRoute(context, new RegistrationScreen());
|
||||||
// } else {
|
} else {
|
||||||
// checkToken(context, new CheckTokenCallback());
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
checkToken(context).then((response) {
|
||||||
|
|
||||||
class CheckTokenCallback extends Callback {
|
print(response.body);
|
||||||
|
Map parsedMap = JSON.decode(response.body);
|
||||||
|
bool active = parsedMap['active'];
|
||||||
|
|
||||||
/// Запускается экран ожидания активации токена.
|
if (active) {
|
||||||
/// В реальности токен активируется в админке вручную,
|
Navigator.of(context).pop();
|
||||||
/// на тестовом сервере токен активируется через несколько минут после создания.
|
// Запускается экран сканера, токен кассы активирован, с его помощью можно делать запросы к pos-api.
|
||||||
|
startScanner(context);
|
||||||
call(BuildContext context) {
|
} else {
|
||||||
pushRoute(context, new FinishRegistrationScreen());
|
// Запускается экран ожидания активации токена.
|
||||||
|
// В реальности токен активируется в админке вручную,
|
||||||
|
// на тестовом сервере токен активируется через несколько минут после создания.
|
||||||
|
pushRoute(context, new FinishRegistrationScreen());
|
||||||
|
}
|
||||||
|
|
||||||
|
}).catchError((error) {
|
||||||
|
print(error.toString());
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,6 +24,7 @@ flutter:
|
|||||||
- assets/splash.png
|
- assets/splash.png
|
||||||
- assets/logout.png
|
- assets/logout.png
|
||||||
- assets/activate_token_message_background.png
|
- assets/activate_token_message_background.png
|
||||||
|
- assets/active_token_message_background.png
|
||||||
|
|
||||||
# To add assets from package dependencies, first ensure the asset
|
# To add assets from package dependencies, first ensure the asset
|
||||||
# is in the lib/ directory of the dependency. Then,
|
# is in the lib/ directory of the dependency. Then,
|
||||||
|
|||||||
Reference in New Issue
Block a user