Navigation improvements

This commit is contained in:
Vicente J. Ruiz Jurado 2018-08-06 11:36:50 +02:00
parent ff854b2a06
commit 0b56a02a0b
9 changed files with 151 additions and 160 deletions

View file

@ -203,7 +203,7 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
return Scaffold( return Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
// FIXME new? // FIXME new?
drawer: MainDrawer.getDrawer(context), drawer: new MainDrawer(context, ActiveFiresPage.routeName),
appBar: new AppBar( appBar: new AppBar(
title: Text(title), title: Text(title),
leading: IconButton( leading: IconButton(

View file

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:share/share.dart'; import 'package:share/share.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'customStepper.dart'; import 'customStepper.dart';
import 'mainDrawer.dart';
import 'generated/i18n.dart'; import 'generated/i18n.dart';
import 'placesAutocompleteUtils.dart'; import 'placesAutocompleteUtils.dart';
@ -83,6 +84,7 @@ class _FireAlertState extends State<FireAlert> {
return Scaffold( return Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
appBar: new AppBar(title: new Text(S.of(context).notifyAFire)), appBar: new AppBar(title: new Text(S.of(context).notifyAFire)),
drawer: new MainDrawer(context, FireAlert.routeName),
body: new CustomStepper( body: new CustomStepper(
currentCustomStep: _currentStep, currentCustomStep: _currentStep,
// type: StepperType.horizontal, // type: StepperType.horizontal,

View file

@ -178,7 +178,8 @@ class _FireNotificationListState extends State<FireNotificationList> {
return Scaffold( return Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
drawer: MainDrawer.getDrawer(context), drawer: new MainDrawer(context, FireNotificationList.routeName),
appBar: new AppBar( appBar: new AppBar(
title: Text(title), title: Text(title),
leading: IconButton( leading: IconButton(

View file

@ -16,6 +16,7 @@ import 'models/appState.dart';
import 'package:bson_objectid/bson_objectid.dart'; import 'package:bson_objectid/bson_objectid.dart';
import 'package:flutter_simple_dependency_injection/injector.dart'; import 'package:flutter_simple_dependency_injection/injector.dart';
import 'fireNotificationList.dart'; import 'fireNotificationList.dart';
class HomePage extends StatefulWidget { class HomePage extends StatefulWidget {
static const String routeName = '/home'; static const String routeName = '/home';
@ -52,9 +53,7 @@ class _HomePageState extends State<HomePage> {
setState(() { setState(() {
store.dispatch(new OnConnectivityChanged(connectionStatus)); store.dispatch(new OnConnectivityChanged(connectionStatus));
if (connectionStatus == ConnectivityResult.none) { if (connectionStatus == ConnectivityResult.none) {
_showDialog(S _showDialog(S.of(context).noConnectivity);
.of(context)
.noConnectivity);
} }
}); });
} }
@ -107,12 +106,11 @@ class _HomePageState extends State<HomePage> {
// color: Colors.white, // color: Colors.white,
); );
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
drawer: MainDrawer.getDrawer(context), drawer: new MainDrawer(context, HomePage.routeName),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: floatingActionButton:
Column(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[ Column(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
@ -172,7 +170,6 @@ class _HomePageState extends State<HomePage> {
child: new Text(S.of(context).appName, child: new Text(S.of(context).appName,
maxLines: 2, maxLines: 2,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: _homeFont), style: _homeFont),
fit: BoxFit.scaleDown, fit: BoxFit.scaleDown,
)), )),
@ -182,8 +179,6 @@ class _HomePageState extends State<HomePage> {
)); ));
} }
void _showDialog(String message) { void _showDialog(String message) {
showDialog<bool>( showDialog<bool>(
context: _scaffoldKey.currentContext, context: _scaffoldKey.currentContext,
@ -240,7 +235,8 @@ class _HomePageState extends State<HomePage> {
/* if (!notif.getRoute(store).isCurrent) { /* if (!notif.getRoute(store).isCurrent) {
// Navigator.push(_scaffoldKey.currentContext, notif.getRoute(store)); // Navigator.push(_scaffoldKey.currentContext, notif.getRoute(store));
} */ } */
Navigator.pushNamed(_scaffoldKey.currentContext, FireNotificationList.routeName); Navigator.pushNamed(
_scaffoldKey.currentContext, FireNotificationList.routeName);
} }
// https://pub.dartlang.org/packages/firebase_messaging#-example-tab- // https://pub.dartlang.org/packages/firebase_messaging#-example-tab-
@ -265,5 +261,4 @@ class _HomePageState extends State<HomePage> {
if (notif != null) store.dispatch(new AddFireNotificationAction(notif)); if (notif != null) store.dispatch(new AddFireNotificationAction(notif));
return notif; return notif;
} }
} }

View file

@ -2,7 +2,6 @@ import 'package:badge/badge.dart';
import 'package:comunes_flutter/comunes_flutter.dart'; import 'package:comunes_flutter/comunes_flutter.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:flutter_simple_dependency_injection/injector.dart';
import 'activeFires.dart'; import 'activeFires.dart';
import 'colors.dart'; import 'colors.dart';
@ -37,30 +36,19 @@ class _ViewModel {
} }
class MainDrawer extends Drawer { class MainDrawer extends Drawer {
MainDrawer(BuildContext context, {key}) MainDrawer(BuildContext context, String currentRoute, {key})
: super(key: key, child: mainDrawer(context)); : super(key: key, child: mainDrawer(context, currentRoute));
static getDrawer(BuildContext context) {
Injector inj = Injector.getInjector();
MainDrawer d;
try {
d = inj.get<MainDrawer>();
} catch (e) {
inj.map<MainDrawer>((i) => new MainDrawer(context), isSingleton: true);
d = inj.get<MainDrawer>();
}
return d;
}
} }
Widget mainDrawer(BuildContext context) { Widget mainDrawer(BuildContext context, String currentRoute) {
return new StoreConnector<AppState, _ViewModel>( return new StoreConnector<AppState, _ViewModel>(
distinct: true, distinct: true,
converter: (store) { converter: (store) {
return new _ViewModel(unreadCount: store.state.fireNotificationsUnread); return new _ViewModel(unreadCount: store.state.fireNotificationsUnread);
}, },
builder: (context, view) { builder: (context, view) {
final bottomTextStyle = new TextStyle(fontSize: 12.0, color: Colors.grey); final bottomTextStyle =
new TextStyle(fontSize: 12.0, color: Colors.grey);
return new ListView( return new ListView(
// Important: Remove any padding from the ListView. // Important: Remove any padding from the ListView.
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
@ -68,7 +56,7 @@ Widget mainDrawer(BuildContext context) {
new GestureDetector( new GestureDetector(
onTap: () { onTap: () {
Navigator.pop(context); Navigator.pop(context);
Navigator.pushNamed(context, '/'); Navigator.popAndPushNamed(context, '/');
}, },
child: new DrawerHeader( child: new DrawerHeader(
child: new Column( child: new Column(
@ -94,22 +82,22 @@ Widget mainDrawer(BuildContext context) {
new ListTile( new ListTile(
leading: const Icon(Icons.whatshot), leading: const Icon(Icons.whatshot),
title: new Text(S.of(context).activeFires), title: new Text(S.of(context).activeFires),
selected: currentRoute == ActiveFiresPage.routeName,
onTap: () { onTap: () {
Navigator.pop(context); Navigator.popAndPushNamed(context, ActiveFiresPage.routeName);
Navigator.pushNamed(context, ActiveFiresPage.routeName);
}, },
), ),
new ListTile( new ListTile(
leading: const Icon(Icons.notifications_active), leading: const Icon(Icons.notifications_active),
selected: currentRoute == FireAlert.routeName,
title: new Text(S.of(context).notifyAFire), title: new Text(S.of(context).notifyAFire),
onTap: () { onTap: () {
// Then close the drawer Navigator.popAndPushNamed(context, FireAlert.routeName);
Navigator.pop(context);
Navigator.pushNamed(context, FireAlert.routeName);
}, },
), ),
new ListTile( new ListTile(
leading: const Icon(Icons.notifications), leading: const Icon(Icons.notifications),
selected: currentRoute == FireNotificationList.routeName,
title: view.unreadCount > 0 title: view.unreadCount > 0
? Badge.after( ? Badge.after(
spacing: 5.0, spacing: 5.0,
@ -118,47 +106,45 @@ Widget mainDrawer(BuildContext context) {
value: ' ${view.unreadCount.toString()} ') value: ' ${view.unreadCount.toString()} ')
: Text(S.of(context).fireNotificationsTitleShort), : Text(S.of(context).fireNotificationsTitleShort),
onTap: () { onTap: () {
// Then close the drawer Navigator.popAndPushNamed(context, FireNotificationList.routeName);
Navigator.pop(context);
Navigator.pushNamed(context, FireNotificationList.routeName);
}, },
), ),
globals.isDevelopment globals.isDevelopment
? new ListTile( ? new ListTile(
leading: const Icon(Icons.map), leading: const Icon(Icons.map),
selected: currentRoute == MonitoredAreasPage.routeName,
title: new Text(S.of(context).monitoredAreasTitle), title: new Text(S.of(context).monitoredAreasTitle),
onTap: () { onTap: () {
Navigator.pop(context); Navigator.pop(context);
Navigator.pushNamed(context, MonitoredAreasPage.routeName); Navigator.popAndPushNamed(
context, MonitoredAreasPage.routeName);
}, },
) )
: null, : null,
new Divider(), new Divider(),
new ListTile( new ListTile(
leading: const Icon(Icons.favorite), leading: const Icon(Icons.favorite),
selected: currentRoute == SupportPage.routeName,
title: new Text(S.of(context).supportThisInitiative), title: new Text(S.of(context).supportThisInitiative),
onTap: () { onTap: () {
// Then close the drawer Navigator.popAndPushNamed(context, SupportPage.routeName);
Navigator.pop(context);
Navigator.pushNamed(context, SupportPage.routeName);
}, },
), ),
new ListTile( new ListTile(
leading: const Icon(Icons.lock), leading: const Icon(Icons.lock),
selected: currentRoute == PrivacyPage.routeName,
title: new Text(S.of(context).privacyPolicy), title: new Text(S.of(context).privacyPolicy),
onTap: () { onTap: () {
// Then close the drawer Navigator.popAndPushNamed(context, PrivacyPage.routeName);
Navigator.pop(context);
Navigator.pushNamed(context, PrivacyPage.routeName);
}, },
), ),
globals.isDevelopment globals.isDevelopment
? new ListTile( ? new ListTile(
leading: const Icon(Icons.bug_report), leading: const Icon(Icons.bug_report),
title: new Text('Sandbox'), title: new Text('Sandbox'),
selected: currentRoute == Sandbox.routeName,
onTap: () { onTap: () {
Navigator.pop(context); Navigator.popAndPushNamed(context, Sandbox.routeName);
Navigator.pushNamed(context, Sandbox.routeName);
}, },
) )
: null, : null,
@ -167,10 +153,12 @@ Widget mainDrawer(BuildContext context) {
applicationName: S.of(context).appName, applicationName: S.of(context).appName,
applicationVersion: globals.appVersion, applicationVersion: globals.appVersion,
applicationIcon: globals.appMediumIcon, applicationIcon: globals.appMediumIcon,
applicationLegalese: S.of(context).appLicense(DateTime.now().year.toString()), applicationLegalese:
S.of(context).appLicense(DateTime.now().year.toString()),
aboutBoxChildren: <Widget>[ aboutBoxChildren: <Widget>[
new SizedBox(height: 10.0), new SizedBox(height: 10.0),
new Text(S.of(context).appMoto), // , style: new TextStyle(fontStyle: FontStyle.italic)), new Text(S.of(context).appMoto),
// , style: new TextStyle(fontStyle: FontStyle.italic)),
new SizedBox(height: 10.0), new SizedBox(height: 10.0),
new Text(S.of(context).NASAAck, style: bottomTextStyle), new Text(S.of(context).NASAAck, style: bottomTextStyle),
// More ? // More ?

View file

@ -5,24 +5,27 @@ import 'package:flutter/services.dart' show rootBundle;
import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:flutter_markdown/flutter_markdown.dart';
import 'globals.dart' as globals; import 'globals.dart' as globals;
import 'mainDrawer.dart';
abstract class MarkdownPage extends StatefulWidget { abstract class MarkdownPage extends StatefulWidget {
final String title; final String title;
final Future<String> file; final Future<String> file;
final String route;
MarkdownPage({this.title, this.file}); MarkdownPage({this.title, this.route, this.file});
@override @override
_MarkdownPageState createState() => _MarkdownPageState createState() =>
_MarkdownPageState(title: this.title, file: this.file); _MarkdownPageState(title: this.title, file: this.file, route: this.route);
} }
class _MarkdownPageState extends State<MarkdownPage> { class _MarkdownPageState extends State<MarkdownPage> {
final String title; final String title;
final String route;
final Future<String> file; final Future<String> file;
String pageData = ""; String pageData = "";
_MarkdownPageState({this.title, this.file}); _MarkdownPageState({this.title, this.file, this.route});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -37,6 +40,7 @@ class _MarkdownPageState extends State<MarkdownPage> {
}); });
return new Scaffold( return new Scaffold(
appBar: new AppBar(title: new Text(title ?? '')), appBar: new AppBar(title: new Text(title ?? '')),
drawer: new MainDrawer(context, route),
body: new Markdown(data: pageData)); body: new Markdown(data: pageData));
} }
} }

View file

@ -1,4 +1,3 @@
import 'package:comunes_flutter/comunes_flutter.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
@ -40,27 +39,25 @@ class MonitoredAreasPage extends StatelessWidget {
builder: (context, view) { builder: (context, view) {
return new Scaffold( return new Scaffold(
appBar: appBar:
new AppBar(title: new Text(S new AppBar(title: new Text(S.of(context).monitoredAreasTitle)),
.of(context) drawer: new MainDrawer(context, MonitoredAreasPage.routeName),
.monitoredAreasTitle)),
drawer: MainDrawer.getDrawer(context),
bottomNavigationBar: new CustomBottomAppBar( bottomNavigationBar: new CustomBottomAppBar(
fabLocation: FloatingActionButtonLocation.centerDocked, fabLocation: FloatingActionButtonLocation.centerDocked,
showNotch: true, showNotch: true,
color: fires100, color: fires100,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
actions: <Widget>[new Flexible(child: actions: <Widget>[
new Padding( new Flexible(
padding: new EdgeInsets.only(left: 10.0, right: 10.0), child: child: new Padding(
new Column( padding: new EdgeInsets.only(left: 10.0, right: 10.0),
child: new Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
new Text(S new Text(S.of(context).mapPrivacy,
.of(context)
.mapPrivacy,
style: new TextStyle( style: new TextStyle(
fontStyle: FontStyle.italic, color: Colors.black38)) fontStyle: FontStyle.italic,
color: Colors.black38))
]))) ])))
]), ]),
body: !(view.monitoredAreas is List) body: !(view.monitoredAreas is List)
@ -72,9 +69,7 @@ class MonitoredAreasPage extends StatelessWidget {
new Padding( new Padding(
padding: new EdgeInsets.only( padding: new EdgeInsets.only(
top: 8.0, bottom: 8.0, left: 0.0, right: 0.0), top: 8.0, bottom: 8.0, left: 0.0, right: 0.0),
child: new Text(S child: new Text(S.of(context).inGreenMonitoredAreas),
.of(context)
.inGreenMonitoredAreas),
), ),
new Flexible( new Flexible(
child: new FlutterMap( child: new FlutterMap(

View file

@ -10,6 +10,7 @@ class PrivacyPage extends MarkdownPage {
PrivacyPage(context) PrivacyPage(context)
: super( : super(
title: S.of(context).privacyPolicy, title: S.of(context).privacyPolicy,
route: routeName,
file: getFileNameOfLang( file: getFileNameOfLang(
dir: 'assets/pages', dir: 'assets/pages',
fileName: 'privacy', fileName: 'privacy',

View file

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'generated/i18n.dart'; import 'generated/i18n.dart';
import 'mainDrawer.dart';
class SupportPage extends StatefulWidget { class SupportPage extends StatefulWidget {
static const String routeName = '/support'; static const String routeName = '/support';
@ -33,12 +34,16 @@ class _SupportPageState extends State<SupportPage> {
key: _scaffoldKey, key: _scaffoldKey,
appBar: appBar:
new AppBar(title: new Text(S.of(context).supportThisInitiative)), new AppBar(title: new Text(S.of(context).supportThisInitiative)),
drawer: new MainDrawer(context, SupportPage.routeName),
body: Padding( body: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: new CenteredColumn(children: <Widget>[ child: new CenteredColumn(children: <Widget>[
new Flexible( new Flexible(
child: new CenteredColumn(children: <Widget>[ child: new CenteredColumn(children: <Widget>[
new Text(S.of(context).supportPageDescription, textAlign: TextAlign.center,), new Text(
S.of(context).supportPageDescription,
textAlign: TextAlign.center,
),
new SizedBox(height: 20.0), new SizedBox(height: 20.0),
buildSupportButton() buildSupportButton()
])) ]))