ios demo version
This commit is contained in:
169
lib/common.dart
169
lib/common.dart
@@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'db.dart';
|
||||
import 'dart:convert';
|
||||
import 'network.dart';
|
||||
import 'resources.dart';
|
||||
import 'strings.dart';
|
||||
@@ -16,23 +17,25 @@ const platform = const MethodChannel('com.dinect.checker/instance_id');
|
||||
|
||||
// Метод обеспечивает замену текущего объекта route новым.
|
||||
pushRouteReplacement(BuildContext context, Widget widget) {
|
||||
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => widget);
|
||||
var route =
|
||||
new MaterialPageRoute<Null>(builder: (BuildContext context) => widget);
|
||||
Navigator.of(context).pushReplacement(route);
|
||||
}
|
||||
|
||||
pushRoute(BuildContext context, Widget widget) {
|
||||
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => widget);
|
||||
var route =
|
||||
new MaterialPageRoute<Null>(builder: (BuildContext context) => widget);
|
||||
Navigator.of(context).push(route);
|
||||
}
|
||||
|
||||
// Добавление route, с возможностью вернуться к предыдущему экрану.
|
||||
faq(SqliteHelper helper, String app, BuildContext context, bool returnToScanner) {
|
||||
faq(SqliteHelper helper, String app, BuildContext context,
|
||||
bool returnToScanner) {
|
||||
pushRoute(context, new FAQScreen(helper, app, returnToScanner));
|
||||
}
|
||||
|
||||
// В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения.
|
||||
logout(BuildContext context, SqliteHelper helper) async {
|
||||
|
||||
String token = await helper.getToken();
|
||||
// String locale = await helper.getLocale();
|
||||
|
||||
@@ -41,9 +44,10 @@ logout(BuildContext context, SqliteHelper helper) async {
|
||||
getDeleteTokenRequest(token).then((response) {
|
||||
helper.clear().then((result) {
|
||||
// helper.close().then((_) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
pushRouteReplacement(context, new SplashScreen()); // Запускаем регистрацию
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
pushRouteReplacement(
|
||||
context, new SplashScreen()); // Запускаем регистрацию
|
||||
// });
|
||||
});
|
||||
}).catchError((error) {
|
||||
@@ -55,19 +59,20 @@ logout(BuildContext context, SqliteHelper helper) async {
|
||||
}
|
||||
};
|
||||
|
||||
showYesNoDialog(context, StringsLocalization.confirmation(), StringsLocalization.askChangeStore(), positiveCallback);
|
||||
showYesNoDialog(context, StringsLocalization.confirmation(),
|
||||
StringsLocalization.askChangeStore(), positiveCallback);
|
||||
}
|
||||
|
||||
forceLogout(String token , BuildContext context) async {
|
||||
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());
|
||||
while (Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
pushRouteReplacement(context, new SplashScreen());
|
||||
// });
|
||||
});
|
||||
});
|
||||
@@ -90,25 +95,58 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
||||
// Могут быть вызваны либо logout либо faq, либо purchase.
|
||||
if (token != null) {
|
||||
platform.setMethodCallHandler((MethodCall call) async {
|
||||
print('flutter handler');
|
||||
print(call.method);
|
||||
|
||||
if (call.method == 'logout') {
|
||||
forceLogout(token, context);
|
||||
} else if (call.method == 'findUserAndPurchase') {
|
||||
|
||||
var userResponse;
|
||||
try {
|
||||
userResponse = await getUserByCard(call.arguments[0],token);
|
||||
} catch (error) {
|
||||
print(error.toString());
|
||||
}
|
||||
|
||||
List<Map> users;
|
||||
|
||||
|
||||
try{
|
||||
users = JSON.decode(userResponse.body);
|
||||
} catch (error) {
|
||||
print(error);
|
||||
}
|
||||
|
||||
print(users.length);
|
||||
|
||||
if (users.length > 0) {
|
||||
String userString = '${users[0]['first_name']} ${users[0]['last_name']}';
|
||||
String card = users[0]['card'];
|
||||
print(userString);
|
||||
print(card);
|
||||
pushRoute(context, new PurchaseScreen(helper, app, JSON.encode(users[0]), card));
|
||||
// var route = new MaterialPageRoute<Null>(
|
||||
// builder: (BuildContext context) =>
|
||||
// new PurchaseScreen(helper, app,));
|
||||
// while (Navigator.of(context).canPop()) {
|
||||
// Navigator.of(context).pop();
|
||||
// }
|
||||
// Navigator.of(context).pushReplacement(route);
|
||||
}
|
||||
|
||||
|
||||
} else if (call.method == 'faq') {
|
||||
faq(helper, app, context, true);
|
||||
} else if(call.method == 'settings') {
|
||||
if (helper == null) {
|
||||
helper = new SqliteHelper();
|
||||
helper.open().then((_) {
|
||||
pushRoute(context, new SettingsScreen(helper, app, true));
|
||||
});
|
||||
} else {
|
||||
pushRoute(context, new SettingsScreen(helper, app, true));
|
||||
}
|
||||
} else if (call.method == 'settings') {
|
||||
pushRoute(context, new SettingsScreen(helper, app, true));
|
||||
} else {
|
||||
String userString = call.arguments[0];
|
||||
print(userString);
|
||||
String card = call.arguments[1];
|
||||
var route = new MaterialPageRoute<Null>(
|
||||
builder: (BuildContext context) =>
|
||||
new PurchaseScreen(helper, app, userString, card));
|
||||
new PurchaseScreen(helper, app, userString, card));
|
||||
while (Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
@@ -116,56 +154,61 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
||||
}
|
||||
});
|
||||
|
||||
// helper.close().then((_){
|
||||
// helper = null;
|
||||
platform.invokeMethod('getEndpoint').then((endpoint) {
|
||||
platform.invokeMethod('getAppToken').then((appToken) async {
|
||||
platform.invokeMethod('startScanner', {
|
||||
'token': token,
|
||||
'url': endpoint,
|
||||
'appToken': appToken,
|
||||
'locale': Intl.defaultLocale,
|
||||
'color': Resources.getPrimaryColor(app).value
|
||||
});
|
||||
});
|
||||
});
|
||||
// });
|
||||
platform.invokeMethod('startScanner', {
|
||||
'token': await platform.invokeMethod('getAppToken'),
|
||||
'url': await platform.invokeMethod('getEndpoint'),
|
||||
'appToken': await platform.invokeMethod('getAppToken'),
|
||||
'locale': Intl.defaultLocale,
|
||||
'color': Resources.getPrimaryColor(app).value
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Запуск диалога с двумя кнопками
|
||||
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)]));
|
||||
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: return StringsLocalization.nominativeRuble();
|
||||
case 840: return StringsLocalization.nominativeDollar();
|
||||
case 980: return StringsLocalization.nominativeHryvna();
|
||||
case 978: return StringsLocalization.nominativeEuro();
|
||||
case 398: return StringsLocalization.nominativeTenge();
|
||||
switch (code) {
|
||||
case 643:
|
||||
return StringsLocalization.nominativeRuble();
|
||||
case 840:
|
||||
return StringsLocalization.nominativeDollar();
|
||||
case 980:
|
||||
return StringsLocalization.nominativeHryvna();
|
||||
case 978:
|
||||
return StringsLocalization.nominativeEuro();
|
||||
case 398:
|
||||
return StringsLocalization.nominativeTenge();
|
||||
}
|
||||
}
|
||||
|
||||
getLocaleTitle(String code) {
|
||||
switch(code) {
|
||||
case 'ru': return 'Русский';
|
||||
case 'en': return 'English';
|
||||
case 'ua': return 'Український';
|
||||
case 'es': return 'Español';
|
||||
switch (code) {
|
||||
case 'ru':
|
||||
return 'Русский';
|
||||
case 'en':
|
||||
return 'English';
|
||||
case 'ua':
|
||||
return 'Український';
|
||||
case 'es':
|
||||
return 'Español';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user