124 lines
3.9 KiB
Dart
124 lines
3.9 KiB
Dart
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);
|
||
new Future.delayed(const Duration(milliseconds: 200), ()
|
||
{
|
||
Navigator.of(context).push(route);
|
||
});
|
||
}
|
||
|
||
// Добавление route, с возможностью вернуться к предыдущему экрану.
|
||
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();
|
||
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:
|
||
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';
|
||
}
|
||
}
|
||
|
||
// Добавил вызов, что-бы AOT компилер не выкинул либу.
|
||
getImage() async {
|
||
return await ImagePicker.pickImage();
|
||
}
|