issue 10730
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
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:checker/screens/splash.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
@@ -19,13 +21,18 @@ const platform = const MethodChannel('com.dinect.checker/instance_id');
|
||||
pushRouteReplacement(BuildContext context, Widget widget) {
|
||||
var route =
|
||||
new MaterialPageRoute<Null>(builder: (BuildContext context) => widget);
|
||||
Navigator.of(context).pushReplacement(route);
|
||||
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);
|
||||
Navigator.of(context).push(route);
|
||||
new MaterialPageRoute<Null>(builder: (BuildContext context) => widget, fullscreenDialog: true);
|
||||
new Future.delayed(const Duration(milliseconds: 200), ()
|
||||
{
|
||||
Navigator.of(context).push(route);
|
||||
});
|
||||
}
|
||||
|
||||
// Добавление route, с возможностью вернуться к предыдущему экрану.
|
||||
@@ -37,24 +44,24 @@ faq(SqliteHelper helper, String app, BuildContext context,
|
||||
// В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения.
|
||||
logout(BuildContext context, SqliteHelper helper) async {
|
||||
String token = await helper.getToken();
|
||||
// String locale = await helper.getLocale();
|
||||
|
||||
VoidCallback positiveCallback = () {
|
||||
if (token != null) {
|
||||
getDeleteTokenRequest(token).then((response) {
|
||||
helper.clear().then((result) {
|
||||
// helper.close().then((_) {
|
||||
// Navigator.of(context).pop();
|
||||
// Navigator.of(context).pop();
|
||||
pushRouteReplacement(context, new SplashScreen()); // Запускаем регистрацию
|
||||
// });
|
||||
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 {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
while (Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -62,56 +69,27 @@ logout(BuildContext context, SqliteHelper helper) async {
|
||||
StringsLocalization.askChangeStore(), positiveCallback);
|
||||
}
|
||||
|
||||
forceLogout(String token, BuildContext context) async {
|
||||
getDeleteTokenRequest(token).then((response) {
|
||||
SqliteHelper helper = new SqliteHelper();
|
||||
helper.open().then((_) {
|
||||
helper.clear().then((_) {
|
||||
// helper.close().then((_) {
|
||||
while (Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
pushRouteReplacement(context, new SplashScreen());
|
||||
// });
|
||||
});
|
||||
});
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
});
|
||||
}
|
||||
|
||||
/// Запуск спецефичной для каждой платформы части приложения - сканера.
|
||||
/// Может производиться с нескольких экранов (splash, finish_registration).
|
||||
startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
||||
if (helper == null) {
|
||||
helper = new SqliteHelper();
|
||||
helper.open().then((_) {
|
||||
startScanner(context, app, helper);
|
||||
});
|
||||
} else {
|
||||
String token = await helper.getToken();
|
||||
// Канал ловит вызовы методов из "нативной" части приложения.
|
||||
// Могут быть вызваны либо exit либо faq, либо purchase.
|
||||
if (token != null) {
|
||||
platform.setMethodCallHandler((MethodCall call) async {
|
||||
print('flutter handler');
|
||||
print(call.method);
|
||||
|
||||
if (call.method == 'findUser') {
|
||||
|
||||
var userResponse;
|
||||
String cardPhone = call.arguments[0];
|
||||
|
||||
try {
|
||||
switch (call.arguments[1]) {
|
||||
case 'card':
|
||||
userResponse = await getUserByCard(cardPhone,token);
|
||||
userResponse = await getUserByCard(cardPhone, token);
|
||||
break;
|
||||
case 'phone':
|
||||
userResponse = await getUserByPhone(cardPhone,token);
|
||||
userResponse = await getUserByPhone(cardPhone, token);
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
print(error.toString());
|
||||
}
|
||||
@@ -119,7 +97,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
||||
List<Map> users;
|
||||
|
||||
|
||||
try{
|
||||
try {
|
||||
users = JSON.decode(userResponse.body);
|
||||
} catch (error) {
|
||||
print(error);
|
||||
@@ -131,8 +109,6 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
||||
startScanner(context, app, helper);
|
||||
throw new FlutterError("Users not found");
|
||||
}
|
||||
|
||||
|
||||
} else if (call.method == 'faq') {
|
||||
faq(helper, app, context, true);
|
||||
} else if (call.method == 'settings') {
|
||||
@@ -150,13 +126,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
||||
|
||||
String card = call.arguments[1];
|
||||
print('$userString, $card');
|
||||
var route = new MaterialPageRoute<Null>(
|
||||
builder: (BuildContext context) =>
|
||||
new PurchaseScreen(helper, app, userString, card));
|
||||
while (Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
Navigator.of(context).pushReplacement(route);
|
||||
pushRouteReplacement(context, new PurchaseScreen(helper, app, userString, card));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -166,12 +136,14 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
||||
'url': await platform.invokeMethod('getEndpoint'),
|
||||
'appToken': await platform.invokeMethod('getAppToken'),
|
||||
'localeCode': StringsLocalization.localeCode,
|
||||
'color': Resources.getPrimaryColor(app).value.toString()
|
||||
'color': Resources
|
||||
.getPrimaryColor(app)
|
||||
.value
|
||||
.toString()
|
||||
});
|
||||
|
||||
platform.invokeMethod('startScanner', args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Запуск диалога с двумя кнопками
|
||||
|
||||
Reference in New Issue
Block a user