Move logout button to settings. Replace logout button in menu with shutdown button.

This commit is contained in:
Ivan Murashov
2018-02-05 20:02:36 +03:00
parent b19381f00c
commit 5f2d67bbc1
23 changed files with 433 additions and 136 deletions

View File

@@ -1,6 +1,5 @@
import 'package:checker/resources.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:checker/common.dart';
import 'package:checker/consts.dart';
@@ -70,14 +69,10 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
child: getMenuItem(help_png, StringsLocalization.help())
));
helper.getToken().then((token){
if (token != null) { // пользователь авторизован
menuItemList.add(new PopupMenuItem(
value: 2,
child: getMenuItem(logout_png, StringsLocalization.logout())
));
}
});
menuItemList.add(new PopupMenuItem(
value: 2,
child: getMenuItem(exit_png, StringsLocalization.exit())
));
return <Widget>[
new PopupMenuButton<int>(
@@ -100,7 +95,8 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
break;
}
case 2: {
logout(context, helper);
platform.invokeMethod('finish');
break;
}
}
}

View File

@@ -45,8 +45,8 @@ logout(BuildContext context, SqliteHelper helper) async {
getDeleteTokenRequest(token).then((response) {
helper.clear().then((result) {
// helper.close().then((_) {
Navigator.of(context).pop();
Navigator.of(context).pop();
// Navigator.of(context).pop();
// Navigator.of(context).pop();
pushRouteReplacement(
context, new SplashScreen()); // Запускаем регистрацию
// });
@@ -93,15 +93,13 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
} else {
String token = await helper.getToken();
// Канал ловит вызовы методов из "нативной" части приложения.
// Могут быть вызваны либо logout либо faq, либо purchase.
// Могут быть вызваны либо exit либо faq, либо purchase.
if (token != null) {
platform.setMethodCallHandler((MethodCall call) async {
print('flutter handler');
print(call.method);
if (call.method == 'logout') {
forceLogout(token, context);
} else if (call.method == 'findUser') {
if (call.method == 'findUser') {
var userResponse;
String cardPhone = call.arguments[0];

View File

@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
const String appName = "Dinect";
// Assets
const String logout_png = 'assets/logout.png';
const String exit_png = 'assets/exit.png';
const String help_png = 'assets/help.png';
const String settings_png = 'assets/settings.png';
const String settings_arrow_png = 'assets/settings_arrow.png';
@@ -23,8 +23,9 @@ const Color greenBackground = const Color(0xff8ae28a);
const Color faqGrey = const Color(0xff5b5b5b);
const Color faqTitlesColor = const Color(0xff404040);
const Color inputFieldBackground = const Color(0xffefefef);
const Color logoutRed = const Color(0xffeb0004);
// Dimens
const double verticalMargin = 28.0;
const double buttonHeight = 48.0;
const double iconHeight = 20.0;
const double iconHeight = 20.0;

View File

@@ -75,8 +75,17 @@ class SqliteHelper {
}
}
Future<Map> getSettings() async {
return await selectAll(tableSettings);
Future<Map> getSettings(bool withSession) async {
Map settings = await selectAll(tableSettings);
if (withSession) {
Map session = await selectAll(tableSession);
if (settings != null && session != null) {
settings.addAll(session);
}
}
return settings;
}
Future<String> getToken() async {
@@ -137,4 +146,4 @@ class SqliteHelper {
Future clear() async {
return await db.delete(tableSession, where: null);
}
}
}

View File

@@ -52,7 +52,8 @@ class MessageLookup extends MessageLookupByLibrary {
"yes" : MessageLookupByLibrary.simpleMessage("Yes"),
"settings" : MessageLookupByLibrary.simpleMessage("Settings"),
"help" : MessageLookupByLibrary.simpleMessage("Help"),
"logout" : MessageLookupByLibrary.simpleMessage("Exit"),
"exit" : MessageLookupByLibrary.simpleMessage("Exit"),
"logout" : MessageLookupByLibrary.simpleMessage("Log Out"),
"currency" : MessageLookupByLibrary.simpleMessage("Currency"),
"locale" : MessageLookupByLibrary.simpleMessage("Language"),
"nominative_ruble": MessageLookupByLibrary.simpleMessage("Ruble"),

View File

@@ -51,7 +51,8 @@ class MessageLookup extends MessageLookupByLibrary {
"yes" : MessageLookupByLibrary.simpleMessage("Si"),
"settings" : MessageLookupByLibrary.simpleMessage("Las configuraciones"),
"help" : MessageLookupByLibrary.simpleMessage("La Ayuda"),
"logout" : MessageLookupByLibrary.simpleMessage("Salir"),
"exit" : MessageLookupByLibrary.simpleMessage("Salir"),
"logout" : MessageLookupByLibrary.simpleMessage("Log Out"),
"currency" : MessageLookupByLibrary.simpleMessage("La Moneda"),
"locale" : MessageLookupByLibrary.simpleMessage("La lengua"),
"nominative_ruble": MessageLookupByLibrary.simpleMessage("Rublo"),

View File

@@ -52,7 +52,8 @@ class MessageLookup extends MessageLookupByLibrary {
"yes" : MessageLookupByLibrary.simpleMessage("Да"),
"settings" : MessageLookupByLibrary.simpleMessage("Настройки"),
"help" : MessageLookupByLibrary.simpleMessage("Справка"),
"logout" : MessageLookupByLibrary.simpleMessage("Выход"),
"exit" : MessageLookupByLibrary.simpleMessage("Закрыть приложение"),
"logout" : MessageLookupByLibrary.simpleMessage("Выйти из аккаунта"),
"currency" : MessageLookupByLibrary.simpleMessage("Валюта"),
"locale" : MessageLookupByLibrary.simpleMessage("Язык"),
"nominative_ruble": MessageLookupByLibrary.simpleMessage("Рубль"),

View File

@@ -51,7 +51,8 @@ class MessageLookup extends MessageLookupByLibrary {
"yes" : MessageLookupByLibrary.simpleMessage("Так"),
"settings" : MessageLookupByLibrary.simpleMessage("Налаштування"),
"help" : MessageLookupByLibrary.simpleMessage("Допомога"),
"logout" : MessageLookupByLibrary.simpleMessage("Вихід"),
"exit" : MessageLookupByLibrary.simpleMessage("Вихід"),
"logout" : MessageLookupByLibrary.simpleMessage("Log Out"),
"currency" : MessageLookupByLibrary.simpleMessage("Валюта"),
"locale" : MessageLookupByLibrary.simpleMessage("Мова"),
"nominative_ruble": MessageLookupByLibrary.simpleMessage("Рубль"),

View File

@@ -7,7 +7,8 @@ class Resources {
}
static String getSplash(String app) {
return 'assets/${app != null ? app : 'pip'}_splash.png';
// app != null ? app :
return 'assets/${'pip'}_splash.png';
}
static Color getPrimaryColor(String app) {
@@ -27,4 +28,4 @@ class Resources {
default: return new Color(0xffffffff);
}
}
}
}

View File

@@ -59,10 +59,11 @@ class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
]);
}
// Если токен активирован, то открывается экран со сканером,
// Если токен активирован, то открывается экран со сканером,
// Если нет, то отправляется запрос на проверку статуса токена.
handleTap() async {
if (_tokenActive) {
Navigator.of(context).pop();
startScanner(context, app, helper);
} else {
if (await platform.invokeMethod('isOnline')) {
@@ -90,7 +91,7 @@ class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
]);
}
/// Метод возвращает контейнер с текстом сообщения и бэкграундом.
/// Метод возвращает контейнер с текстом сообщения и бэкграундом.
getMessage() {
return new Container(height: _tokenActive ? 72.0 : 108.0,
decoration: _getDecorationForMessageField(),
@@ -99,7 +100,7 @@ class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
child: new Center(child: getMessageTextWidget()));
}
/// Метод возвращает виджет с текстом сообщения, всеми его привязками и стилями.
/// Метод возвращает виджет с текстом сообщения, всеми его привязками и стилями.
getMessageTextWidget() {
return new Text(getMessageString(), textAlign: TextAlign.center,
style: new TextStyle(
@@ -123,4 +124,4 @@ class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
_tokenActive ? active_token_bg_png : activate_token_bg_png),
fit: _tokenActive ? BoxFit.fitWidth : BoxFit.fill));
}
}
}

View File

@@ -15,7 +15,8 @@ class SettingsScreen extends BaseScreen {
SettingsScreen(helper, app, this.returnToScanner) : super(helper, app);
@override State createState() => new SettingsState(helper, app, returnToScanner);
@override State createState() =>
new SettingsState(helper, app, returnToScanner);
}
class MenuItem {
@@ -29,6 +30,7 @@ class MenuItem {
class SettingsState extends BaseState<SettingsScreen> {
List<MenuItem> menuItems = [
new MenuItem('', ''),
new MenuItem('', ''),
new MenuItem('', '')
];
@@ -42,27 +44,35 @@ class SettingsState extends BaseState<SettingsScreen> {
}
@override Widget build(BuildContext ctx) {
helper.getSettings().then((info) {
helper.getSettings(true).then((info) {
setState(() {
menuItems[0].title = StringsLocalization.currency();
menuItems[1].title = StringsLocalization.locale();
menuItems[2].title = StringsLocalization.logout();
menuItems[0].selectedValue = info['currency'].toString();
menuItems[1].selectedValue = info['locale'] == null ? Intl.defaultLocale : info['locale'].toString();
menuItems[1].selectedValue =
info['locale'] == null ? Intl.defaultLocale : info['locale'];
menuItems[2].selectedValue =
info['token'] == null ? '' : getTokenSuffix(info['token']);
});
});
return new WillPopScope(onWillPop: onWillPop, child: getMainWidget());
}
String getTokenSuffix(String token) {
return token.substring(token.length - 4, token.length);
}
Widget getMainWidget() {
return new Scaffold(appBar: getAppBar(),
body: getScreenContent());
body: getScreenContent());
}
@override
Widget getScreenContent() {
return new Container(
margin: new EdgeInsets.only(top: 16.0),
child: new ListView(children: getSettings()));
margin: new EdgeInsets.only(top: 16.0),
child: new ListView(children: getSettings()));
}
@override
@@ -73,33 +83,58 @@ class SettingsState extends BaseState<SettingsScreen> {
List<Widget> getSettings() {
List<Widget> widgets = new List();
for (int i = 0; i < menuItems.length; i++) {
if (menuItems[i].selectedValue != '') {
widgets.add(getSettingsItem(() => onPressed(menuItems.indexOf(menuItems[i])),
if (menuItems[i].selectedValue.toString() != '') {
widgets.add(
getSettingsItem(() => onPressed(menuItems.indexOf(menuItems[i])),
menuItems[i].title,
i == 0 ? getCurrencyTitle(int.parse(menuItems[i].selectedValue)) : getLocaleTitle(menuItems[i].selectedValue)));
getValue(i)));
}
}
return widgets;
}
String getValue(int position) {
switch (position) {
case 0 :
return getCurrencyTitle(int.parse(menuItems[position].selectedValue));
case 1 :
return getLocaleTitle(menuItems[position].selectedValue);
default :
return null;
}
}
Widget getSettingsItem(VoidCallback onPressed, String title, String value) {
return new Container(
height: 56.0,
padding: new EdgeInsets.only(left: 8.0),
child: (new FlatButton(
onPressed: onPressed,
child: new Row(children: <Widget>[
new Expanded(child: new Text(title, style: new TextStyle(
fontWeight: FontWeight.w600,
color: faqGrey,
fontSize: 14.0))),
new Text(value,
style: new TextStyle(
fontWeight: FontWeight.w400,
color: faqGrey,
fontSize: 14.0)),
getArrow()
]))));
height: 56.0,
padding: new EdgeInsets.only(left: 8.0),
child: (new FlatButton(
onPressed: onPressed,
child: getRow(title, value))));
}
Widget getRow(String title, String value) {
if (value == null) {
return new Row(children: <Widget>[
new Text(title, style: new TextStyle(
fontWeight: FontWeight.w600,
color: faqGrey,
fontSize: 14.0))
]);
} else {
return new Row(children: <Widget>[
new Expanded(child: new Text(title, style: new TextStyle(
fontWeight: FontWeight.w600,
color: faqGrey,
fontSize: 14.0))),
new Text(value,
style: new TextStyle(
fontWeight: FontWeight.w400,
color: faqGrey,
fontSize: 14.0)),
getArrow()
]);
}
}
void onPressed(int position) {
@@ -108,12 +143,14 @@ class SettingsState extends BaseState<SettingsScreen> {
return pushRoute(context, new CurrenciesScreen(helper, app));
case 1 :
return pushRoute(context, new LanguagesScreen(helper, app));
case 2 :
return logout(context, helper);
}
}
Widget getArrow() {
return new Container(margin: new EdgeInsets.only(left: 8.0),
child: new Image.asset(settings_arrow_png, height: 42.0));
child: new Image.asset(settings_arrow_png, height: 42.0));
}
@override
@@ -122,10 +159,10 @@ class SettingsState extends BaseState<SettingsScreen> {
}
onWillPop() {
if(returnToScanner) {
if (returnToScanner) {
return startScanner(context, app, helper);
} else {
return true;
}
}
}
}

View File

@@ -50,7 +50,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
void initWithSystemValue() {
platform.invokeMethod('getLocale').then((locale) {
helper.getSettings().then((settings) {
helper.getSettings(false).then((settings) {
if (settings == null) {
createSettingsTable(locale);
} else {

View File

@@ -112,6 +112,7 @@ class StringsLocalization {
static String idNotFound() => Intl.message('ID_not_found', name: 'ID_not_found', locale: Intl.defaultLocale);
static String settings() => Intl.message('settings', name: 'settings', locale: Intl.defaultLocale);
static String help() => Intl.message('help', name: 'help', locale: Intl.defaultLocale);
static String exit() => Intl.message('exit', name: 'exit', locale: Intl.defaultLocale);
static String logout() => Intl.message('logout', name: 'logout', locale: Intl.defaultLocale);
static String currency() => Intl.message('currency', name: 'currency', locale: Intl.defaultLocale);
static String locale() => Intl.message('locale', name: 'locale', locale: Intl.defaultLocale);