iOS crypto target
This commit is contained in:
@@ -1,31 +1,15 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:checker/screens/faq.dart';
|
||||
import 'package:checker/screens/purchase.dart';
|
||||
import 'package:checker/screens/registration.dart';
|
||||
import 'package:checker/screens/settings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import 'db.dart';
|
||||
import 'dart:convert';
|
||||
import 'network.dart';
|
||||
import 'resources.dart';
|
||||
import 'strings.dart';
|
||||
|
||||
// Канал для взаимодействия с кодом платформы.
|
||||
const platform = const MethodChannel('com.dinect.checker/instance_id');
|
||||
|
||||
// Метод обеспечивает замену текущего объекта route новым.
|
||||
pushRouteReplacement(BuildContext context, Widget widget) {
|
||||
var route =
|
||||
new MaterialPageRoute<Null>(builder: (BuildContext context) => widget);
|
||||
new Future.delayed(const Duration(milliseconds: 200), () {
|
||||
Navigator.of(context).pushReplacement(route);
|
||||
});
|
||||
}
|
||||
|
||||
pushRoute(BuildContext context, Widget widget) {
|
||||
var route =
|
||||
new MaterialPageRoute<Null>(builder: (BuildContext context) => widget, fullscreenDialog: true);
|
||||
@@ -41,54 +25,6 @@ faq(SqliteHelper helper, String app, BuildContext context,
|
||||
pushRoute(context, new FAQScreen(helper, app, returnToScanner));
|
||||
}
|
||||
|
||||
// В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения.
|
||||
logout(BuildContext context, SqliteHelper helper) async {
|
||||
String token = await helper.getToken();
|
||||
VoidCallback positiveCallback = () {
|
||||
if (token != null) {
|
||||
getDeleteTokenRequest(token).then((response) {
|
||||
helper.clear().then((result) {
|
||||
platform.invokeMethod('getFlavor').then((flavor) {
|
||||
while (Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
pushRouteReplacement(context, new RegistrationScreen(helper, flavor));
|
||||
});
|
||||
});
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
});
|
||||
} else {
|
||||
while (Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
showYesNoDialog(context, StringsLocalization.confirmation(),
|
||||
StringsLocalization.askChangeStore(), positiveCallback);
|
||||
}
|
||||
|
||||
// Запуск диалога с двумя кнопками
|
||||
showYesNoDialog(BuildContext context, String title, String content,
|
||||
VoidCallback positiveCallback) {
|
||||
showDialog(
|
||||
context: context,
|
||||
child: new AlertDialog(
|
||||
title: new Text(title),
|
||||
content: new Text(content),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text(StringsLocalization.no()),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}),
|
||||
new FlatButton(
|
||||
child: new Text(StringsLocalization.yes()),
|
||||
onPressed: positiveCallback)
|
||||
]));
|
||||
}
|
||||
|
||||
getCurrencyTitle(int code) {
|
||||
switch (code) {
|
||||
case 643:
|
||||
@@ -116,8 +52,3 @@ getLocaleTitle(String code) {
|
||||
return 'Español';
|
||||
}
|
||||
}
|
||||
|
||||
// Добавил вызов, что-бы AOT компилер не выкинул либу.
|
||||
getImage() async {
|
||||
return await ImagePicker.pickImage();
|
||||
}
|
||||
|
||||
@@ -77,15 +77,17 @@ class SqliteHelper {
|
||||
}
|
||||
|
||||
Future<Map> getSettings(bool withSession) async {
|
||||
|
||||
|
||||
Map results = new Map();
|
||||
Map settings = await selectAll(tableSettings);
|
||||
|
||||
results.addAll(settings);
|
||||
if (settings != null && settings.isNotEmpty) {
|
||||
results.addAll(settings);
|
||||
}
|
||||
|
||||
if (withSession) {
|
||||
Map session = await selectAll(tableSession);
|
||||
if (settings != null && session != null) {
|
||||
if (session != null && session.isNotEmpty) {
|
||||
results.addAll(session);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ main() {
|
||||
helper.open().then((_) {
|
||||
helper.getLocale().then((locale) {
|
||||
if (locale == null) {
|
||||
initWithSystemValue(app, appName, helper);
|
||||
initWithSystemValue(app, appName, locale, helper);
|
||||
} else {
|
||||
start(app, appName, locale, helper);
|
||||
}
|
||||
@@ -29,9 +29,9 @@ main() {
|
||||
});
|
||||
}
|
||||
|
||||
initWithSystemValue(String app, String name, SqliteHelper helper) {
|
||||
initWithSystemValue(String app, String name, String locale, SqliteHelper helper) {
|
||||
helper.getSettings(false).then((settings) {
|
||||
if (settings == null) {
|
||||
if (settings.isEmpty) {
|
||||
createSettingsTable(app, name, helper);
|
||||
} else {
|
||||
start(app, name, locale, helper);
|
||||
|
||||
@@ -135,11 +135,7 @@ class FAQScreenState<T> extends BaseState<FAQScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// onWillPop() {
|
||||
// if(returnToScanner) {
|
||||
// return startScanner(context, app, helper);
|
||||
// } else {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
@override bool isAutomaticallyImplyLeading() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,28 +59,25 @@ class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
|
||||
|
||||
// Если токен активирован, то открывается экран со сканером,
|
||||
// Если нет, то отправляется запрос на проверку статуса токена.
|
||||
handleTap() async {
|
||||
handleTap() {
|
||||
print('tokenActive: $_tokenActive');
|
||||
if (_tokenActive) {
|
||||
new Future.delayed(const Duration(milliseconds: 200), () {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
Navigator.of(context).pop(true);
|
||||
} else {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
String token = await helper.getToken();
|
||||
getCheckTokenStatusRequest(token).then((response) {
|
||||
Map parsedMap = JSON.decode(response.body);
|
||||
|
||||
// Обновить экран, заменить сообщение о необходимости активации токена, на сообщние о том, что токен активен.
|
||||
setState(() {
|
||||
_tokenActive = parsedMap['active'];
|
||||
platform.invokeMethod('isOnline').then((isOnline) {
|
||||
if (isOnline ) {
|
||||
helper.getToken().then((token) {
|
||||
getCheckTokenStatusRequest(token).then((response) {
|
||||
setState(() {
|
||||
_tokenActive = JSON.decode(response.body)['active'];
|
||||
});
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
helper.createSession(merchantID, posID, parsedMap['token']).then((_) {
|
||||
new Future.delayed(const Duration(milliseconds: 200), () {
|
||||
var route = new MaterialPageRoute<bool>(builder: (BuildContext context) => new FinishRegistrationScreen(helper, app), fullscreenDialog: true);
|
||||
Navigator.of(context).pushReplacement(route).then((b) {
|
||||
Navigator.of(context).push(route).then((b) {
|
||||
print('finish registration closed: $b');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:checker/base/base_screen.dart';
|
||||
import 'package:checker/base/base_state.dart';
|
||||
import 'package:checker/common.dart';
|
||||
import 'package:checker/consts.dart';
|
||||
import 'package:checker/db.dart';
|
||||
import 'package:checker/network.dart';
|
||||
import 'package:checker/screens/currencies.dart';
|
||||
import 'package:checker/screens/languages.dart';
|
||||
import 'package:checker/screens/splash.dart';
|
||||
import 'package:checker/strings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -42,12 +46,18 @@ class SettingsState extends BaseState<SettingsScreen> {
|
||||
this.returnToScanner = returnToScanner;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
print('init state!');
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override Widget build(BuildContext ctx) {
|
||||
helper.getSettings(true).then((info) {
|
||||
setState(() {
|
||||
print('currency: ${info['currency']}');
|
||||
print('locale: ${info['locale']}');
|
||||
print('token: ${info['token']}');
|
||||
// print('currency: ${info['currency']}');
|
||||
// print('locale: ${info['locale']}');
|
||||
// print('token: ${info['token']}');
|
||||
menuItems[0].title = StringsLocalization.currency();
|
||||
menuItems[1].title = StringsLocalization.locale();
|
||||
menuItems[2].title = StringsLocalization.logout();
|
||||
@@ -152,6 +162,55 @@ class SettingsState extends BaseState<SettingsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения.
|
||||
logout(BuildContext context, SqliteHelper helper) async {
|
||||
String token = await helper.getToken();
|
||||
VoidCallback positiveCallback = () {
|
||||
if (token != null) {
|
||||
getDeleteTokenRequest(token).then((response) {
|
||||
helper.clear().then((result) {
|
||||
while (Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => new SplashScreen(helper, app));
|
||||
new Future.delayed(const Duration(milliseconds: 200), () {
|
||||
Navigator.of(context).pushReplacement(route);
|
||||
});
|
||||
});
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
});
|
||||
} else {
|
||||
while (Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
showYesNoDialog(context, StringsLocalization.confirmation(),
|
||||
StringsLocalization.askChangeStore(), positiveCallback);
|
||||
}
|
||||
|
||||
// Запуск диалога с двумя кнопками
|
||||
showYesNoDialog(BuildContext context, String title, String content,
|
||||
VoidCallback positiveCallback) {
|
||||
showDialog(
|
||||
context: context,
|
||||
child: new AlertDialog(
|
||||
title: new Text(title),
|
||||
content: new Text(content),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text(StringsLocalization.no()),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}),
|
||||
new FlatButton(
|
||||
child: new Text(StringsLocalization.yes()),
|
||||
onPressed: positiveCallback)
|
||||
]));
|
||||
}
|
||||
|
||||
Widget getArrow() {
|
||||
return new Container(margin: new EdgeInsets.only(left: 8.0),
|
||||
child: new Image.asset(settings_arrow_png, height: 42.0));
|
||||
@@ -161,12 +220,4 @@ class SettingsState extends BaseState<SettingsScreen> {
|
||||
String getTitle() {
|
||||
return StringsLocalization.settings();
|
||||
}
|
||||
|
||||
// onWillPop() {
|
||||
// if (returnToScanner) {
|
||||
// return startScanner(context, app, helper);
|
||||
// } else {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -78,24 +78,23 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
]));
|
||||
}
|
||||
|
||||
startRegistration(Widget screen) {
|
||||
new Future.delayed(const Duration(milliseconds: 200), () {
|
||||
var route = new MaterialPageRoute<String>(
|
||||
builder: (BuildContext context) => screen, fullscreenDialog: true);
|
||||
Navigator.of(context).push(route).then((token) {
|
||||
_initAndStartScanner(context, app, token, helper);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Запуск следующего экрана приложения.
|
||||
showNextScreen() async {
|
||||
|
||||
String token = await helper.getToken();
|
||||
|
||||
// В случае, если в приложении отсутствует токен,
|
||||
// необходимо запустить регистрацию кассы.
|
||||
if (token == null) {
|
||||
|
||||
new Future.delayed(const Duration(milliseconds: 200), () {
|
||||
var route = new MaterialPageRoute<bool>(
|
||||
builder: (BuildContext context) => new RegistrationScreen(helper, app), fullscreenDialog: true);
|
||||
Navigator.of(context).push(route).then((b) {
|
||||
_initAndStartScanner(context, app, token, helper);
|
||||
});
|
||||
});
|
||||
|
||||
// pushRoute(context, new RegistrationScreen(helper, app));
|
||||
startRegistration(new RegistrationScreen(helper, app));
|
||||
} else {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
getCheckTokenStatusRequest(token).then((statusResponse) {
|
||||
@@ -114,7 +113,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
int code = statusResponse.statusCode;
|
||||
if (code == 404) {
|
||||
helper.clear().then((result) {
|
||||
pushRouteReplacement(context, new RegistrationScreen(helper, app));
|
||||
startRegistration(new RegistrationScreen(helper, app));
|
||||
});
|
||||
} else {
|
||||
Map status = JSON.decode(statusResponse.body);
|
||||
@@ -146,8 +145,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
getCreateTokenRequest({'merchant_shop': merchantID, 'pos': posID})
|
||||
.then((response) {
|
||||
if (response.statusCode == 409) {
|
||||
pushRouteReplacement(
|
||||
context, new FinishRegistrationScreen(helper, app));
|
||||
startRegistration(new FinishRegistrationScreen(helper, app));
|
||||
} else if (response.statusCode == 201) {
|
||||
clearToken(response, helper);
|
||||
}
|
||||
@@ -161,8 +159,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
helper.clear().then((_) {
|
||||
Map parsedMap = JSON.decode(response.body);
|
||||
getDeleteTokenRequest(parsedMap['token']).then((_) {
|
||||
Navigator.of(context).pop();
|
||||
pushRouteReplacement(context, new RegistrationScreen(helper, app));
|
||||
startRegistration(new RegistrationScreen(helper, app));
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
});
|
||||
@@ -186,6 +183,8 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
userResponse.then((response) {
|
||||
List<Map> users;
|
||||
|
||||
|
||||
|
||||
try {
|
||||
users = JSON.decode(response.body);
|
||||
} catch (error) {
|
||||
@@ -203,10 +202,9 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
faq(helper, app, context, true);
|
||||
} else if (call.method == 'settings') {
|
||||
new Future.delayed(const Duration(milliseconds: 200), () {
|
||||
var route = new MaterialPageRoute<bool>(
|
||||
var route = new MaterialPageRoute<Null>(
|
||||
builder: (BuildContext context) => new SettingsScreen(helper, app, true), fullscreenDialog: true);
|
||||
Navigator.of(context).push(route).then((b) {
|
||||
print('purchase closed: $b');
|
||||
Navigator.of(context).push(route).then((_) {
|
||||
_initAndStartScanner(context, app, token, helper);
|
||||
});
|
||||
});
|
||||
@@ -246,10 +244,9 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
|
||||
startScanner(String token, String userString, String card) {
|
||||
new Future.delayed(const Duration(milliseconds: 200), () {
|
||||
var route = new MaterialPageRoute<bool>(
|
||||
var route = new MaterialPageRoute<Null>(
|
||||
builder: (BuildContext context) => new PurchaseScreen(helper, app, userString, card), fullscreenDialog: true);
|
||||
Navigator.of(context).push(route).then((b) {
|
||||
print('purchase closed: $b');
|
||||
Navigator.of(context).push(route).then((_) {
|
||||
_initAndStartScanner(context, app, token, helper);
|
||||
});
|
||||
});
|
||||
@@ -272,4 +269,4 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user