Исправление замечаний
This commit is contained in:
@@ -42,10 +42,6 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
||||
fit: BoxFit.cover)));
|
||||
}
|
||||
|
||||
void onStart() {
|
||||
print("ON START!");
|
||||
}
|
||||
|
||||
/// Возвращает контейнер с всеми виджетами экрана.
|
||||
Widget getScreenContent();
|
||||
|
||||
@@ -88,8 +84,8 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
||||
pushRoute(context, new FAQScreen(false));
|
||||
break;
|
||||
}
|
||||
case 0: {
|
||||
logout(context);
|
||||
case 2: {
|
||||
logout(context, helper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ abstract class SettingsBaseState<T extends StatefulWidget> extends BaseState<T>
|
||||
@override
|
||||
Widget getScreenContent() {
|
||||
|
||||
print('getScreenContent: $selectedItem');
|
||||
getSelectedValue();
|
||||
|
||||
|
||||
|
||||
@@ -31,21 +31,21 @@ faq(BuildContext context, bool returnToScanner) {
|
||||
}
|
||||
|
||||
// В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения.
|
||||
logout(BuildContext context) async {
|
||||
logout(BuildContext context, SqliteHelper helper) async {
|
||||
|
||||
SqliteHelper helper = new SqliteHelper();
|
||||
await helper.open();
|
||||
String token = await helper.getToken();
|
||||
String locale = await helper.getLocale();
|
||||
|
||||
VoidCallback positiveCallback = () {
|
||||
if (token != null) {
|
||||
deleteToken(token).then((response) {
|
||||
print(response.body);
|
||||
platform.invokeMethod('removeKeys').then((result) {
|
||||
deleteToken(token, locale).then((response) {
|
||||
helper.clear().then((result) {
|
||||
helper.close().then((_) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
pushRouteReplacement(context, new SplashScreen()); // Запускаем регистрацию
|
||||
});
|
||||
});
|
||||
}).catchError((error) {
|
||||
print(error.toString());
|
||||
});
|
||||
@@ -60,8 +60,7 @@ logout(BuildContext context) async {
|
||||
|
||||
forceLogout(String token , BuildContext context) async {
|
||||
|
||||
deleteToken(token).then((response) {
|
||||
print(response.body);
|
||||
deleteToken(token, 'ru').then((response) {
|
||||
SqliteHelper helper = new SqliteHelper();
|
||||
helper.open().then((_) {
|
||||
helper.clear().then((_) {
|
||||
@@ -87,16 +86,13 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
||||
if (token != null) {
|
||||
platform.setMethodCallHandler((MethodCall call) async {
|
||||
|
||||
print('call.method: ${call.method}');
|
||||
if (call.method == 'logout') {
|
||||
forceLogout(token, context);
|
||||
} else if (call.method == 'faq') {
|
||||
faq(context, true);
|
||||
} else {
|
||||
String userString = call.arguments[0];
|
||||
print('user: ${userString}');
|
||||
String card = call.arguments[1];
|
||||
print('card: ${card}');
|
||||
var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => new PurchaseScreen(userString, card));
|
||||
Navigator.of(context).pushReplacement(route);
|
||||
}
|
||||
@@ -133,6 +129,8 @@ getCurrencyTitle(int 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.nominativeEuro();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,14 +83,12 @@ class SqliteHelper {
|
||||
Future<String> getToken() async {
|
||||
Map session = await selectAll(tableSession);
|
||||
String token = session != null ? session[columnToken] : null;
|
||||
print('token: {$token}');
|
||||
return token;
|
||||
}
|
||||
|
||||
Future<String> getMerchantID() async {
|
||||
Map session = await selectAll(tableSession);
|
||||
String merchantID = session != null ? session[columnMerchantID] : null;
|
||||
print('merchantID: {$merchantID}');
|
||||
return merchantID;
|
||||
}
|
||||
|
||||
@@ -103,27 +101,23 @@ class SqliteHelper {
|
||||
Map session = await selectAll(tableSession);
|
||||
int docID = session != null ? session[columnDocID] : 0;
|
||||
db.update(tableSession, {columnDocID: docID + 1});
|
||||
print('docid: {$docID}');
|
||||
return docID;
|
||||
}
|
||||
|
||||
Future<String> getLocale() async {
|
||||
Map settings = await selectAll(tableSettings);
|
||||
String locale = settings != null ? settings[columnLocale] : null;
|
||||
print('locale: {$locale}');
|
||||
return locale;
|
||||
}
|
||||
|
||||
Future<int> getCurrency() async {
|
||||
Map settings = await selectAll(tableSettings);
|
||||
int currency = settings != null ? settings[columnCurrency] : null;
|
||||
print('currency: {$currency}');
|
||||
return currency;
|
||||
}
|
||||
|
||||
Future<int> saveCurrency(int currency) async {
|
||||
db.update(tableSettings, {columnCurrency: currency});
|
||||
print('currency: {$currency}');
|
||||
return currency;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,12 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"plural_dollar": MessageLookupByLibrary.simpleMessage("Долларов"),
|
||||
"nominative_hryvna": MessageLookupByLibrary.simpleMessage("Гривна"),
|
||||
"singular_hryvna": MessageLookupByLibrary.simpleMessage("Гривны"),
|
||||
"plural_hryvna": MessageLookupByLibrary.simpleMessage("Гривен")
|
||||
"plural_hryvna": MessageLookupByLibrary.simpleMessage("Гривен"),
|
||||
"nominative_tenge": MessageLookupByLibrary.simpleMessage("Тенге"),
|
||||
"singular_tenge": MessageLookupByLibrary.simpleMessage("Тенге"),
|
||||
"plural_tenge": MessageLookupByLibrary.simpleMessage("Тенге"),
|
||||
"nominative_euro": MessageLookupByLibrary.simpleMessage("Евро"),
|
||||
"singular_euro": MessageLookupByLibrary.simpleMessage("Евро"),
|
||||
"plural_euro": MessageLookupByLibrary.simpleMessage("Евро")
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ final httpClient = createHttpClient();
|
||||
// Попытка создать токен для кассы.
|
||||
// В случае если токен для кассы уже существует, вернется ошибка 409.
|
||||
// На сервере есть ограничение в 40 токенов.
|
||||
createToken(String merchantId, String posID) async {
|
||||
createToken(String merchantId, String posID, String locale) async {
|
||||
|
||||
// Поле description - необязательное.
|
||||
var body = {
|
||||
@@ -16,15 +16,15 @@ createToken(String merchantId, String posID) async {
|
||||
'pos': posID,
|
||||
};
|
||||
|
||||
return httpClient.post(url + 'tokens/?_dmapptoken=' + appToken, body: body);
|
||||
return httpClient.post(url + 'tokens/?_dmapptoken=' + appToken, body: body, headers: {'Accept-Language': locale});
|
||||
}
|
||||
|
||||
// Проверка статуса токена. В ответе приходит параметр active, который может быть либо true, либо false,.
|
||||
checkTokenStatus(String token) async {
|
||||
return httpClient.get(url + 'tokens/' + token + '?_dmapptoken=' + appToken);
|
||||
checkTokenStatus(String token, String locale) async {
|
||||
return httpClient.get(url + 'tokens/' + token + '?_dmapptoken=' + appToken, headers: {'Accept-Language': locale});
|
||||
}
|
||||
|
||||
// Удаление токена на сервере.
|
||||
deleteToken(String token) async {
|
||||
return httpClient.delete(url + 'tokens/' + token + '?_dmapptoken=' + appToken);
|
||||
deleteToken(String token, String locale) async {
|
||||
return httpClient.delete(url + 'tokens/' + token + '?_dmapptoken=' + appToken, headers: {'Accept-Language': locale});
|
||||
}
|
||||
@@ -15,7 +15,7 @@ class CurrenciesScreen extends BaseScreen {
|
||||
|
||||
class _CurrenciesState extends SettingsBaseState<CurrenciesScreen> {
|
||||
|
||||
List<int> currencies = const [643, 840, 980];
|
||||
List<int> currencies = const [643, 840, 980, 978, 398];
|
||||
|
||||
_CurrenciesState(SqliteHelper helper, String app) : super(helper, app);
|
||||
|
||||
@@ -26,8 +26,10 @@ class _CurrenciesState extends SettingsBaseState<CurrenciesScreen> {
|
||||
String ruble = StringsLocalization.nominativeRuble();
|
||||
String dollar = StringsLocalization.nominativeDollar();
|
||||
String hryvna = StringsLocalization.nominativeHryvna();
|
||||
String euro = StringsLocalization.nominativeEuro();
|
||||
String tenge = StringsLocalization.nominativeTenge();
|
||||
|
||||
return [ruble, dollar, hryvna];
|
||||
return [ruble, dollar, hryvna, euro, tenge];
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:checker/strings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:checker/base/base_state.dart';
|
||||
@@ -46,9 +47,10 @@ class FAQScreenState<T> extends BaseState<FAQScreen> {
|
||||
|
||||
FAQScreenState(this.returnToScanner);
|
||||
final bool returnToScanner;
|
||||
String app;
|
||||
|
||||
@override String getTitle() {
|
||||
return "FAQ";
|
||||
return StringsLocalization.help();
|
||||
}
|
||||
|
||||
@override String getHint() {
|
||||
@@ -56,7 +58,18 @@ class FAQScreenState<T> extends BaseState<FAQScreen> {
|
||||
}
|
||||
|
||||
@override Widget build(BuildContext context) {
|
||||
return getScreenContent();
|
||||
if (app == null) {
|
||||
platform.invokeMethod('getFlavor').then((flavor) {
|
||||
setState(() {
|
||||
app = flavor;
|
||||
});
|
||||
});
|
||||
}
|
||||
return new Scaffold(appBar: getAppBar(),body: getScreenContent());
|
||||
}
|
||||
|
||||
@override List<Widget> getMenuButtons() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Метод возвращает ListView с блоками faq.
|
||||
|
||||
@@ -66,8 +66,8 @@ class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
|
||||
} else {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
String token = await helper.getToken();
|
||||
checkTokenStatus(token).then((response) {
|
||||
print(response.body);
|
||||
String locale = await helper.getLocale();
|
||||
checkTokenStatus(token, locale).then((response) {
|
||||
Map parsedMap = JSON.decode(response.body);
|
||||
|
||||
// Обновить экран, заменить сообщение о необходимости активации токена, на сообщние о том, что токен активен.
|
||||
|
||||
@@ -38,7 +38,6 @@ class LanguagesState extends SettingsBaseState<LanguagesScreen> {
|
||||
void getSelectedValue() {
|
||||
helper.getLocale().then((locale) {
|
||||
setState(() {
|
||||
print(selectedItem);
|
||||
selectedItem = getOptions().indexOf(getLocaleTitle(locale));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,7 +60,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
@override Widget getScreenContent() {
|
||||
return new Column(
|
||||
children: <Widget>[new Expanded(child: new ListView(children: <Widget>[
|
||||
getValueWithDescription(StringsLocalization.userName(), user['first_name'] == null ? '' : user['first_name']),
|
||||
getValueWithDescription(StringsLocalization.buyer(), user['first_name'] == null ? '' : user['first_name']),
|
||||
getValueWithDescription(StringsLocalization.card(), card),
|
||||
getValueWithDescription(StringsLocalization.reward(), loyalty),
|
||||
getHintLabel(),
|
||||
@@ -123,10 +123,12 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
|
||||
String token = await helper.getToken();
|
||||
String locale = await helper.getLocale();
|
||||
|
||||
var headers = {
|
||||
'DM-Authorization': 'dmapptoken $appToken',
|
||||
'Authorization': 'dmtoken ${token}'
|
||||
'Authorization': 'dmtoken ${token}',
|
||||
'Accept-Language': locale
|
||||
};
|
||||
|
||||
httpClient.get(url, headers: headers).then((response) {
|
||||
@@ -216,6 +218,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
purchaseInProgress = true;
|
||||
|
||||
String token = await helper.getToken();
|
||||
String locale = await helper.getLocale();
|
||||
helper.getMerchantID().then((result) {
|
||||
|
||||
String url = user['purchases_url'];
|
||||
@@ -230,7 +233,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
|
||||
var headers = {
|
||||
'DM-Authorization': 'dmapptoken $appToken',
|
||||
'Authorization': 'dmtoken ${token}'
|
||||
'Authorization': 'dmtoken ${token}',
|
||||
'Accept-Language': locale
|
||||
};
|
||||
|
||||
httpClient.post(url, body: body, headers: headers).then((response) {
|
||||
|
||||
@@ -88,8 +88,8 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
|
||||
_register() async {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
String posID = await helper.getPosID();
|
||||
|
||||
createToken(dinCode, posID).then((response) {
|
||||
String locale = await helper.getLocale();
|
||||
createToken(dinCode, posID, locale).then((response) {
|
||||
setState(() {
|
||||
error = null;
|
||||
loading = false;
|
||||
|
||||
@@ -37,7 +37,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
return getScreenContent();
|
||||
}
|
||||
|
||||
@override void onStart() {
|
||||
void onStart() {
|
||||
helper.getSettings().then((info) {
|
||||
if (info == null) {
|
||||
platform.invokeMethod('getCurrency').then((currency) {
|
||||
@@ -113,6 +113,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
/// Запуск следующего экрана приложения.
|
||||
showNextScreen() async {
|
||||
String token = await helper.getToken();
|
||||
String locale = await helper.getLocale();
|
||||
|
||||
// В случае, если в приложении отсутствует токен,
|
||||
// необходимо запустить регистрацию кассы.
|
||||
@@ -120,7 +121,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
pushRouteReplacement(context, new RegistrationScreen(helper, app));
|
||||
} else {
|
||||
if (await platform.invokeMethod('isOnline')) {
|
||||
checkTokenStatus(token).then((statusResponse) {
|
||||
checkTokenStatus(token, locale).then((statusResponse) {
|
||||
handleStatusResponse(statusResponse, helper);
|
||||
}).catchError((error) {
|
||||
handleError(error.toString());
|
||||
@@ -134,7 +135,6 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
/// Если токен не активен, попробовать создать его еще раз.
|
||||
handleStatusResponse(var statusResponse, SqliteHelper helper) async {
|
||||
int code = statusResponse.statusCode;
|
||||
print('resp: ${code}');
|
||||
|
||||
if (code == 404) {
|
||||
helper.clear().then((result) {
|
||||
@@ -164,8 +164,9 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
_createToken(SqliteHelper helper) async {
|
||||
String merchantID = await helper.getMerchantID();
|
||||
String posID = await helper.getPosID();
|
||||
String locale = await helper.getLocale();
|
||||
|
||||
createToken(merchantID, posID).then((response) {
|
||||
createToken(merchantID, posID, locale).then((response) {
|
||||
if (response.statusCode == 409) {
|
||||
pushRouteReplacement(context, new FinishRegistrationScreen(helper, app));
|
||||
} else if (response.statusCode == 201) {
|
||||
@@ -177,10 +178,11 @@ class _SplashScreenState extends BaseState<SplashScreen> {
|
||||
}
|
||||
|
||||
/// Очищаем бд, делаем запрос на удаление токена.
|
||||
void clearToken(Response response, SqliteHelper helper) {
|
||||
Future clearToken(Response response, SqliteHelper helper) async {
|
||||
String locale = await helper.getLocale();
|
||||
helper.clear().then((_) {
|
||||
Map parsedMap = JSON.decode(response.body);
|
||||
deleteToken(parsedMap['token']).then((_) {
|
||||
deleteToken(parsedMap['token'], locale).then((_) {
|
||||
Navigator.of(context).pop();
|
||||
pushRouteReplacement(context, new RegistrationScreen(helper, app));
|
||||
}).catchError((error) {
|
||||
|
||||
@@ -50,6 +50,16 @@ class StringsLocalization {
|
||||
singular = singularHryvna();
|
||||
plural = pluralHryvna();
|
||||
break;
|
||||
case 978:
|
||||
nominative = nominativeHryvna();
|
||||
singular = singularHryvna();
|
||||
plural = pluralHryvna();
|
||||
break;
|
||||
case 398:
|
||||
nominative = nominativeTenge();
|
||||
singular = singularTenge();
|
||||
plural = pluralTenge();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,13 +69,11 @@ class StringsLocalization {
|
||||
|
||||
static String confirmPurchase(String val, int code) {
|
||||
String trimmedVal =val.substring(0, val.length - 3);
|
||||
print(trimmedVal);
|
||||
return sprintf(Intl.message('confirm_purchase', name: 'confirm_purchase', locale: Intl.defaultLocale), [trimmedVal, declineCurrency(int.parse(trimmedVal), code)]);
|
||||
}
|
||||
|
||||
static String purchaseCompleted(String val, int code) {
|
||||
String trimmedVal =val.substring(0, val.length - 3);
|
||||
print(trimmedVal);
|
||||
return sprintf(Intl.message('purchase_complite', name: 'purchase_complite', locale: Intl.defaultLocale), [val, declineCurrency(int.parse(trimmedVal), code)]);
|
||||
}
|
||||
|
||||
@@ -82,7 +90,6 @@ class StringsLocalization {
|
||||
static String appActivated() => Intl.message('app_activ', name: 'app_activ', locale: Intl.defaultLocale);
|
||||
static String completeRegistration() => Intl.message('complite_activ', name: 'complite_activ', locale: Intl.defaultLocale);
|
||||
static String cardScanner() => Intl.message('card_scaner', name: 'card_scaner', locale: Intl.defaultLocale);
|
||||
static String userName() => Intl.message('user_name', name: 'user_name', locale: Intl.defaultLocale);
|
||||
static String card() => Intl.message('card', name: 'card', locale: Intl.defaultLocale);
|
||||
static String reward() => Intl.message('reward', name: 'reward', locale: Intl.defaultLocale);
|
||||
static String sum() => Intl.message('sum', name: 'sum', locale: Intl.defaultLocale);
|
||||
@@ -102,6 +109,11 @@ class StringsLocalization {
|
||||
static String singularRuble() => Intl.message('singular_ruble', name: 'singular_ruble', locale: Intl.defaultLocale);
|
||||
static String pluralRuble() => Intl.message('plural_ruble', name: 'plural_ruble', locale: Intl.defaultLocale);
|
||||
|
||||
static String nominativeEuro() => Intl.message('nominative_euro', name: 'nominative_euro', locale: Intl.defaultLocale);
|
||||
static String singularEuro() => Intl.message('singular_euro', name: 'singular_euro', locale: Intl.defaultLocale);
|
||||
static String pluralEuro() => Intl.message('plural_euro', name: 'plural_euro', locale: Intl.defaultLocale);
|
||||
|
||||
|
||||
static String nominativeDollar() => Intl.message('nominative_dollar', name: 'nominative_dollar', locale: Intl.defaultLocale);
|
||||
static String singularDollar() => Intl.message('singular_dollar', name: 'singular_dollar', locale: Intl.defaultLocale);
|
||||
static String pluralDollar() => Intl.message('plural_dollar', name: 'plural_dollar', locale: Intl.defaultLocale);
|
||||
@@ -110,4 +122,8 @@ class StringsLocalization {
|
||||
static String singularHryvna() => Intl.message('singular_hryvna', name: 'singular_hryvna', locale: Intl.defaultLocale);
|
||||
static String pluralHryvna() => Intl.message('plural_hryvna', name: 'plural_hryvna', locale: Intl.defaultLocale);
|
||||
|
||||
static String nominativeTenge() => Intl.message('nominative_tenge', name: 'nominative_tenge', locale: Intl.defaultLocale);
|
||||
static String singularTenge() => Intl.message('singular_tenge', name: 'singular_tenge', locale: Intl.defaultLocale);
|
||||
static String pluralTenge() => Intl.message('plural_tenge', name: 'plural_tenge', locale: Intl.defaultLocale);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user