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

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

@@ -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));
}
}