Исправлены баги

This commit is contained in:
Ivan Murashov
2017-09-26 12:51:30 +03:00
parent 7a1dc84fa1
commit ac7146f46e
7 changed files with 58 additions and 60 deletions

View File

@@ -84,7 +84,7 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
break;
}
case 1: {
pushRoute(context, new FAQScreen(false));
pushRoute(context, new FAQScreen(helper, app, false));
break;
}
case 2: {

View File

@@ -26,8 +26,8 @@ pushRoute(BuildContext context, Widget widget) {
}
// Добавление route, с возможностью вернуться к предыдущему экрану.
faq(BuildContext context, bool returnToScanner) {
pushRoute(context, new FAQScreen(returnToScanner));
faq(SqliteHelper helper, String app, BuildContext context, bool returnToScanner) {
pushRoute(context, new FAQScreen(helper, app, returnToScanner));
}
// В методе отправляется запрос на удаление токена кассы, очищаются SharedPreferences приложения.
@@ -93,7 +93,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
if (call.method == 'logout') {
forceLogout(token, context);
} else if (call.method == 'faq') {
faq(context, true);
faq(helper, app, context, true);
} else if(call.method == 'settings') {
if (helper == null) {
helper = new SqliteHelper();
@@ -108,8 +108,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
String card = call.arguments[1];
var route = new MaterialPageRoute<Null>(
builder: (BuildContext context) =>
new PurchaseScreen(
userString, card));
new PurchaseScreen(helper, app, userString, card));
while (Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
const String appName = "Autobonus";
const String appName = "PIP";
// Assets
const String logout_png = 'assets/logout.png';

View File

@@ -1,5 +1,7 @@
import 'dart:async';
import 'package:checker/base/base_screen.dart';
import 'package:checker/db.dart';
import 'package:checker/resources.dart';
import 'package:checker/strings.dart';
import 'package:flutter/material.dart';
@@ -62,17 +64,22 @@ class EntryItem extends StatelessWidget {
}
}
class FAQScreen extends StatefulWidget {
class FAQScreen extends BaseScreen {
FAQScreen(this.b);
final bool b;
FAQScreen(SqliteHelper helper, String app,
this.returnToScanner) : super(helper, app);
@override State createState() => new FAQScreenState<FAQScreen>(b);
final bool returnToScanner;
@override State createState() => new FAQScreenState<FAQScreen>(returnToScanner, helper, app);
}
class FAQScreenState<T> extends BaseState<FAQScreen> {
FAQScreenState(this.returnToScanner);
FAQScreenState(this.returnToScanner, SqliteHelper helper, String app) {
this.helper = helper;
this.app = app;
}
bool returnToScanner;
@@ -87,7 +94,7 @@ class FAQScreenState<T> extends BaseState<FAQScreen> {
}
@override Widget build(BuildContext context) {
if (app == null) {
if (data == null) {
platform.invokeMethod('getFlavor').then((flavor) {
initPhoneAndUrl().then((_) {
setState(() {

View File

@@ -1,3 +1,4 @@
import 'package:checker/base/base_screen.dart';
import 'package:checker/db.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -13,14 +14,15 @@ import 'package:checker/base/base_state.dart';
import 'package:checker/screens/purchase_success.dart';
/// Экран проведения покупки.
class PurchaseScreen extends StatefulWidget {
PurchaseScreen(this.user, this.card);
class PurchaseScreen extends BaseScreen {
PurchaseScreen(helper, app, this.user, this.card) : super(helper, app);
final String user;
final String card;
@override
State createState() => new PurchaseScreenState<PurchaseScreen>(user, card);
State createState() => new PurchaseScreenState<PurchaseScreen>(helper, app, user, card);
}
class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
@@ -29,9 +31,11 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
/// (удаляет запрещенные символы до их отображаения).
TextEditingController controller = new TextEditingController();
PurchaseScreenState(String userString, String card) {
PurchaseScreenState(SqliteHelper helper, String app, String userString, String card) {
this.user = JSON.decode(userString);
this.card = card;
this.helper = helper;
this.app = app;
}
@override
@@ -62,18 +66,18 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
return new Column(children: <Widget>[
new Expanded(
child: new ListView(children: <Widget>[
getValueWithDescription(StringsLocalization.buyer(),
user['first_name'] == null ? '' : user['first_name']),
getValueWithDescription(StringsLocalization.card(), card),
getValueWithDescription(StringsLocalization.reward(), loyalty),
getHintLabel(),
getInputField(),
wrapButton(getScreenMargins(36.0), getCompleteButton()),
wrapButton(
getScreenMargins(24.0),
getScanButton(context, StringsLocalization.scan(),
Resources.getPrimaryColor(app)))
]))
getValueWithDescription(StringsLocalization.buyer(),
user['first_name'] == null ? '' : user['first_name']),
getValueWithDescription(StringsLocalization.card(), card),
getValueWithDescription(StringsLocalization.reward(), loyalty),
getHintLabel(),
getInputField(),
wrapButton(getScreenMargins(36.0), getCompleteButton()),
wrapButton(
getScreenMargins(24.0),
getScanButton(context, StringsLocalization.scan(),
Resources.getPrimaryColor(app)))
]))
]);
}
@@ -185,7 +189,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
child: new AlertDialog(
title: new Text(StringsLocalization.confirmation()),
content:
new Text(StringsLocalization.confirmPurchase(val, currency)),
new Text(StringsLocalization.confirmPurchase(val, currency)),
actions: <Widget>[
new FlatButton(
child: new Text(StringsLocalization.no()),
@@ -254,7 +258,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
this.loyalty = '${user['discount']}%';
} else {
double loyaltyVal = (double.parse(bonuses['amount_to_bonus'][1]) /
bonuses['amount_to_bonus'][0]) * 100;
bonuses['amount_to_bonus'][0]) * 100;
this.loyalty = '${loyaltyVal.toStringAsFixed(0)}%';
}
}

View File

@@ -28,7 +28,10 @@ class MenuItem {
class SettingsState extends BaseState<SettingsScreen> {
List<MenuItem> menuItems;
List<MenuItem> menuItems = [
new MenuItem('', ''),
new MenuItem('', '')
];
bool returnToScanner;
@@ -39,22 +42,14 @@ class SettingsState extends BaseState<SettingsScreen> {
}
@override Widget build(BuildContext ctx) {
if (menuItems == null) {
menuItems = [
new MenuItem('', ''),
new MenuItem('', '')
];
helper.getSettings().then((info) {
setState(() {
menuItems[0].title = StringsLocalization.currency();
menuItems[1].title = StringsLocalization.locale();
menuItems[0].selectedValue = info['currency'].toString();
menuItems[1].selectedValue =
info['locale'] == null ? Intl.defaultLocale : info['locale']
.toString();
});
helper.getSettings().then((info) {
setState(() {
menuItems[0].title = StringsLocalization.currency();
menuItems[1].title = StringsLocalization.locale();
menuItems[0].selectedValue = info['currency'].toString();
menuItems[1].selectedValue = info['locale'] == null ? Intl.defaultLocale : info['locale'].toString();
});
}
});
return new WillPopScope(onWillPop: onWillPop, child: getMainWidget());
}
@@ -77,16 +72,11 @@ class SettingsState extends BaseState<SettingsScreen> {
List<Widget> getSettings() {
List<Widget> widgets = new List();
if (menuItems != null) {
for (int i = 0; i < menuItems.length; i++) {
if (menuItems[i].selectedValue != '') {
widgets.add(
getSettingsItem(() => onPressed(menuItems.indexOf(menuItems[i])),
menuItems[i].title,
i == 0 ? getCurrencyTitle(
int.parse(menuItems[i].selectedValue)) : getLocaleTitle(
menuItems[i].selectedValue)));
}
for (int i = 0; i < menuItems.length; i++) {
if (menuItems[i].selectedValue != '') {
widgets.add(getSettingsItem(() => onPressed(menuItems.indexOf(menuItems[i])),
menuItems[i].title,
i == 0 ? getCurrencyTitle(int.parse(menuItems[i].selectedValue)) : getLocaleTitle(menuItems[i].selectedValue)));
}
}
return widgets;
@@ -115,10 +105,8 @@ class SettingsState extends BaseState<SettingsScreen> {
void onPressed(int position) {
switch (position) {
case 0 :
menuItems = null;
return pushRoute(context, new CurrenciesScreen(helper, app));
case 1 :
menuItems = null;
return pushRoute(context, new LanguagesScreen(helper, app));
}
}