Move logout button to settings. Replace logout button in menu with shutdown button.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user