Поправил отзывчивость кнопок валют на экране валюты, исправил отображение названий валюты на экранах проведения покупки (рубль, рубля, рублей) для русской локали

This commit is contained in:
kifio
2017-09-12 09:38:17 +03:00
parent e8788f72a3
commit d23ca1c991
16 changed files with 292 additions and 137 deletions

View File

@@ -23,9 +23,9 @@ class _CurrenciesState extends SettingsBaseState<CurrenciesScreen> {
@override
List<String> getOptions() {
String ruble = StringsLocalization.ruble();
String dollar = StringsLocalization.dollar();
String hryvna = StringsLocalization.hryvna();
String ruble = StringsLocalization.nominativeRuble();
String dollar = StringsLocalization.nominativeDollar();
String hryvna = StringsLocalization.nominativeHryvna();
return [ruble, dollar, hryvna];
}

View File

@@ -55,6 +55,10 @@ class FAQScreenState<T> extends BaseState<FAQScreen> {
return null;
}
@override Widget build(BuildContext context) {
return getScreenContent();
}
/// Метод возвращает ListView с блоками faq.
@override Widget getScreenContent() {
return new WillPopScope(onWillPop: onWillPop, child: new ListView.builder(

View File

@@ -1,28 +1,41 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:convert'; // Пакет для обработки json с ответом от сервера.
import 'dart:convert';
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/base/base_state.dart';
import 'package:checker/strings.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class FinishRegistrationScreen extends StatefulWidget {
@override State createState() => new _RegistrationScreenState();
class FinishRegistrationScreen extends BaseScreen {
FinishRegistrationScreen(helper, app) : super(helper, app);
@override State createState() => new RegistrationScreenState(helper, app);
}
class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
RegistrationScreenState(SqliteHelper helper, String app) {
this.helper = helper;
this.app = app;
}
bool _tokenActive = false;
String _merchantID;
String _merchantID = '';
@override void onStart() {
helper.getMerchantID().then((result) {
setState(() {
_merchantID = result;
@override Widget build(BuildContext context) {
if (_merchantID == '') {
helper.getMerchantID().then((result) {
setState(() {
_merchantID = result;
});
});
});
}
return getMainWidget();
}
@override String getTitle() {
@@ -54,7 +67,6 @@ class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
if (await platform.invokeMethod('isOnline')) {
String token = await helper.getToken();
checkTokenStatus(token).then((response) {
print(response.body);
Map parsedMap = JSON.decode(response.body);
@@ -72,23 +84,29 @@ class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
}
@override getTextWidget() {
return new Row(children: <Widget>[new Text(_merchantID != null ? _merchantID : '',
style: new TextStyle(color: Colors.black, fontSize: 16.0))]);
return new Row(
children: <Widget>[new Text(_merchantID != null ? _merchantID : '',
style: new TextStyle(color: Colors.black, fontSize: 16.0))
]);
}
/// Метод возвращает контейнер с текстом сообщения и бэкграундом.
getMessage() {
return new Container(height: _tokenActive ? 72.0 : 108.0, decoration: _getDecorationForMessageField(),
margin: new EdgeInsets.only(top: 20.0, left: 12.0, right: 12.0),
padding: new EdgeInsets.only(bottom: 22.0, left: 14.0, right: 14.0),
child: new Center(child: getMessageTextWidget()));
return new Container(height: _tokenActive ? 72.0 : 108.0,
decoration: _getDecorationForMessageField(),
margin: new EdgeInsets.only(top: 20.0, left: 12.0, right: 12.0),
padding: new EdgeInsets.only(bottom: 22.0, left: 14.0, right: 14.0),
child: new Center(child: getMessageTextWidget()));
}
/// Метод возвращает виджет с текстом сообщения, всеми его привязками и стилями.
getMessageTextWidget() {
return new Text(getMessageString(), textAlign: TextAlign.center,
style: new TextStyle(height: 1.5, fontWeight: FontWeight.bold, fontSize: 14.0,
color: _tokenActive ? tokenActiveTextColor : tokenActivateTextColor));
style: new TextStyle(
height: 1.5, fontWeight: FontWeight.bold, fontSize: 14.0,
color: _tokenActive
? tokenActiveTextColor
: tokenActivateTextColor));
}
/// Получаем текст сообщения, в зависимости от статуса активации.
@@ -101,7 +119,8 @@ class _RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
/// Фоновое изображение для сообщения.
Decoration _getDecorationForMessageField() {
return new BoxDecoration(image: new DecorationImage(
image: new ExactAssetImage(_tokenActive ? active_token_bg_png : activate_token_bg_png),
image: new ExactAssetImage(
_tokenActive ? active_token_bg_png : activate_token_bg_png),
fit: _tokenActive ? BoxFit.fitWidth : BoxFit.fill));
}
}

View File

@@ -1,3 +1,4 @@
import 'package:checker/db.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:convert';
@@ -34,8 +35,21 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
this.card = card;
}
@override void onStart() {
getLoyalty(user['loyalty_url']);
@override Widget build(BuildContext ctx) {
if (helper == null) {
helper = new SqliteHelper();
helper.open().then((_) {
if (app == null) {
platform.invokeMethod('getFlavor').then((flavor) {
app = flavor;
setState(() {
getLoyalty(user['loyalty_url']);
});
});
}
});
}
return getMainWidget();
}
bool purchaseInProgress = false;
@@ -126,8 +140,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
this.loyalty = '${user['discount']}%';
} else {
List amountToBonus = bonuses['amount_to_bonus'];
double loyalityVal = (double.parse(amountToBonus[1]) / amountToBonus[0]) * 100;
this.loyalty = '${loyalityVal.toStringAsFixed(0)}%';
double loyaltyVal = (double.parse(amountToBonus[1]) / amountToBonus[0]) * 100;
this.loyalty = '${loyaltyVal.toStringAsFixed(0)}%';
}
});
}).catchError((error) {
@@ -136,6 +150,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
}
}
// TODO: Переделать? чтобы работало хорошо
String _cleanupNumber(String text){
String tmp = text
.replaceAll(' ', '')
@@ -174,23 +189,25 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
onPurchaseClick() {
String val = _parseSum(controller.text);
showDialog(context: context, child: new AlertDialog(
title: new Text(StringsLocalization.confirmation()),
content: new Text(StringsLocalization.confirmPurchase(val)),
actions: <Widget>[
new FlatButton(
child: new Text(StringsLocalization.no()),
onPressed: () {
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text(StringsLocalization.yes()),
onPressed: () {
purchase(val);
},
)
]));
helper.getCurrency().then((currency) {
showDialog(context: context, child: new AlertDialog(
title: new Text(StringsLocalization.confirmation()),
content: new Text(StringsLocalization.confirmPurchase(val, currency)),
actions: <Widget>[
new FlatButton(
child: new Text(StringsLocalization.no()),
onPressed: () {
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text(StringsLocalization.yes()),
onPressed: () {
purchase(val);
},
)
]));
});
}
purchase(String sumTotal) async {
@@ -221,14 +238,13 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
print(response.body);
Map parsedMap = JSON.decode(response.body);
Navigator.of(context).pop();
if (parsedMap.containsKey('errors')) {
List<String> errors = parsedMap['errors'];
// TODO: ПОказывать сообщение с ошибкой!
Scaffold.of(context).showSnackBar(new SnackBar(content: new Text(errors[0])));
} else {
helper.close().then((_) {
Navigator.of(context).pop();
pushRouteReplacement(context, new PurchaseSuccessScreen(sumTotal, user['first_name'] == null ? '' : user['first_name']));
});
pushRouteReplacement(context, new PurchaseSuccessScreen(sumTotal, user['first_name'] == null ? '' : user['first_name'], helper, app));
}
}).catchError((error) {

View File

@@ -1,26 +1,36 @@
import 'package:flutter/material.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/strings.dart';
import 'package:checker/base/base_state.dart';
import 'package:flutter/material.dart';
/// Экран проведения покупки.
class PurchaseSuccessScreen extends StatefulWidget {
PurchaseSuccessScreen(this.val, this.name);
PurchaseSuccessScreen(this.val, this.name, this.helper, this.app);
final String val;
final String name;
final String app;
final SqliteHelper helper;
@override State createState() => new PurchaseSuccessScreenState(val, name);
@override State createState() =>
new PurchaseSuccessScreenState(val, name, helper, app);
}
class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
PurchaseSuccessScreenState(this.sum, this.username);
PurchaseSuccessScreenState(String sum, String username, SqliteHelper helper,
String app) {
this.sum = sum;
this.username = username;
this.helper = helper;
this.app = app;
}
String sum;
String username;
String sum, username;
int currency;
@override String getTitle() {
return StringsLocalization.carryingPurchase();
@@ -30,6 +40,17 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
return null;
}
@override Widget build(BuildContext context) {
if (currency == null) {
helper.getCurrency().then((currency) {
setState(() {
this.currency = currency;
});
});
}
return getMainWidget();
}
@override Widget getScreenContent() {
return new Column(children: <Widget>[
getValueWithDescription(StringsLocalization.buyer(), username),
@@ -50,14 +71,22 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
}
getSuccessMessage() {
return new Row(children: <Widget>[new Expanded(child: new Container(margin: new EdgeInsets.only(top: 20.0), height: 64.0,
decoration: new BoxDecoration(color: greenBackground),
child: new Center(child: new Text(getMessageTitle(), textAlign: TextAlign.center,
style: new TextStyle(fontWeight: FontWeight.bold, color: tokenActiveTextColor)))))]);
return new Row(children: <Widget>[new Expanded(child: new Container(
margin: new EdgeInsets.only(top: 20.0), height: 64.0,
decoration: new BoxDecoration(color: greenBackground),
child: new Center(
child: new Text(getMessageTitle(), textAlign: TextAlign.center,
style: new TextStyle(fontWeight: FontWeight.bold,
color: tokenActiveTextColor)))))
]);
}
getMessageTitle() {
return StringsLocalization.purchaseCompleted(sum);
if (currency != null) {
return StringsLocalization.purchaseCompleted(sum, currency);
} else {
return '';
}
}
}

View File

@@ -1,23 +1,35 @@
import 'package:checker/base/base_screen.dart';
import 'package:checker/screens/finish_registration.dart';
import 'package:flutter/material.dart';
import 'dart:convert'; // Пакет для обработки json с ответом от сервера.
import 'dart:convert';
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/base/base_state.dart';
import 'package:checker/screens/finish_registration.dart';
import 'package:checker/strings.dart';
import 'package:flutter/material.dart';
// Пакет для обработки json с ответом от сервера.
/// Экран регистрации магазина и кассы.
class RegistrationScreen extends BaseScreen {
RegistrationScreen(helper, app) : super(helper, app);
@override State createState() => new _RegistrationScreenState();
@override State createState() => new RegistrationScreenState(helper, app);
}
class _RegistrationScreenState extends BaseState<RegistrationScreen> {
class RegistrationScreenState extends BaseState<RegistrationScreen> {
RegistrationScreenState(SqliteHelper helper, String app) {
this.helper = helper;
this.app = app;
}
@override Widget build(BuildContext ctx) {
return getMainWidget();
}
@override String getTitle() {
return StringsLocalization.registration();
@@ -30,13 +42,14 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
/// Список виджетов, автоматически прокручиваемый вверх при открытии клавиатуры.
@override Widget getScreenContent() {
return new Container(
child: new ListView(children: <Widget>[
new Column(children: <Widget>[
getLogo(),
getHintLabel(),
getInputField(),
getButton()])
]));
child: new ListView(children: <Widget>[
new Column(children: <Widget>[
getLogo(),
getHintLabel(),
getInputField(),
getButton()
])
]));
}
@override getTextWidget() {
@@ -49,7 +62,7 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
/// Возвращает кнопку регистрации.
getButton() {
return new Container(margin: new EdgeInsets.only(top: 36.0), child:
buildRaisedButton(StringsLocalization.signUp(), getOnPressed()));
buildRaisedButton(StringsLocalization.signUp(), getOnPressed()));
}
// Возвращает обработчик нажатий на кнопку регистрации.
@@ -74,11 +87,9 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
/// Получение от платформы id установки, формирование запроса на получение токена, сохранение токена.
_register() async {
if (await platform.invokeMethod('isOnline')) {
String posID = await helper.getPosID();
createToken(dinCode, posID).then((response) {
setState(() {
error = null;
loading = false;
@@ -90,8 +101,7 @@ class _RegistrationScreenState extends BaseState<RegistrationScreen> {
if (response.statusCode == 201) {
helper.createSession(dinCode, posID, parsedMap['token']).then((_) {
helper.close();
pushRouteReplacement(context, new FinishRegistrationScreen());
pushRouteReplacement(context, new FinishRegistrationScreen(helper, app));
});
} else {
setState(() {

View File

@@ -61,7 +61,9 @@ class SettingsState extends BaseState<SettingsScreen> {
List<Widget> getSettings() {
List<Widget> widgets = new List();
for (MenuItem item in menuItems) {
widgets.add(getSettingsItem(item));
if (item.selectedValue != '') {
widgets.add(getSettingsItem(item));
}
}
return widgets;
}
@@ -77,15 +79,19 @@ class SettingsState extends BaseState<SettingsScreen> {
fontWeight: FontWeight.w600,
color: faqGrey,
fontSize: 14.0))),
new Text(getCurrencyTitle(int.parse(item.selectedValue)), style: new TextStyle(
fontWeight: FontWeight.w400, color: faqGrey, fontSize: 14.0)),
new Text(getCurrencyTitle(int.parse(item.selectedValue)),
style: new TextStyle(
fontWeight: FontWeight.w400,
color: faqGrey,
fontSize: 14.0)),
getArrow()
]))));
}
void onPressed(int position) {
switch (position) {
case 0 : return pushRoute(context, new CurrenciesScreen(helper, app));
case 0 :
return pushRoute(context, new CurrenciesScreen(helper, app));
}
}

View File

@@ -20,7 +20,20 @@ class SplashScreen extends StatefulWidget {
class _SplashScreenState extends BaseState<SplashScreen> {
@override Widget getMainWidget() {
@override Widget build(BuildContext ctx) {
if (helper == null) {
helper = new SqliteHelper();
helper.open().then((_) {
if (app == null) {
platform.invokeMethod('getFlavor').then((flavor) {
app = flavor;
setState(() {
onStart();
});
});
}
});
}
return getScreenContent();
}
@@ -110,10 +123,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
checkTokenStatus(token).then((statusResponse) {
handleStatusResponse(statusResponse, helper);
}).catchError((error) {
helper.close().then((_) {
print(error.toString());
return false;
});
handleError(error.toString());
});
}
}
@@ -157,12 +167,13 @@ class _SplashScreenState extends BaseState<SplashScreen> {
createToken(merchantID, posID).then((response) {
if (response.statusCode == 409) {
helper.close();
pushRouteReplacement(context, new FinishRegistrationScreen());
pushRouteReplacement(context, new FinishRegistrationScreen(helper, app));
} else if (response.statusCode == 201) {
clearToken(response, helper);
}
}).catchError((error) => print(error.toString()));
}).catchError((error) {
handleError(error.toString());
});
}
/// Очищаем бд, делаем запрос на удаление токена.
@@ -173,9 +184,16 @@ class _SplashScreenState extends BaseState<SplashScreen> {
Navigator.of(context).pop();
pushRouteReplacement(context, new RegistrationScreen(helper, app));
}).catchError((error) {
helper.close();
print(error.toString());
handleError(error.toString());
});
});
}
/// Закрываем соединение, логируем ошибку.
void handleError(String error) {
helper.close().then((_) {
print(error.toString());
return false;
});
}
}