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(
key: _scaffoldKey,
// FIXME new?
drawer: MainDrawer.getDrawer(context),
drawer: new MainDrawer(context, ActiveFiresPage.routeName),
appBar: new AppBar(
title: Text(title),
leading: IconButton(

View file

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

View file

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

View file

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

View file

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

View file

@ -5,24 +5,27 @@ import 'package:flutter/services.dart' show rootBundle;
import 'package:flutter_markdown/flutter_markdown.dart';
import 'globals.dart' as globals;
import 'mainDrawer.dart';
abstract class MarkdownPage extends StatefulWidget {
final String title;
final Future<String> file;
final String route;
MarkdownPage({this.title, this.file});
MarkdownPage({this.title, this.route, this.file});
@override
_MarkdownPageState createState() =>
_MarkdownPageState(title: this.title, file: this.file);
_MarkdownPageState(title: this.title, file: this.file, route: this.route);
}
class _MarkdownPageState extends State<MarkdownPage> {
final String title;
final String route;
final Future<String> file;
String pageData = "";
_MarkdownPageState({this.title, this.file});
_MarkdownPageState({this.title, this.file, this.route});
@override
Widget build(BuildContext context) {
@ -37,6 +40,7 @@ class _MarkdownPageState extends State<MarkdownPage> {
});
return new Scaffold(
appBar: new AppBar(title: new Text(title ?? '')),
drawer: new MainDrawer(context, route),
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_map/flutter_map.dart';
import 'package:flutter_redux/flutter_redux.dart';
@ -40,27 +39,25 @@ class MonitoredAreasPage extends StatelessWidget {
builder: (context, view) {
return new Scaffold(
appBar:
new AppBar(title: new Text(S
.of(context)
.monitoredAreasTitle)),
drawer: MainDrawer.getDrawer(context),
new AppBar(title: new Text(S.of(context).monitoredAreasTitle)),
drawer: new MainDrawer(context, MonitoredAreasPage.routeName),
bottomNavigationBar: new CustomBottomAppBar(
fabLocation: FloatingActionButtonLocation.centerDocked,
showNotch: true,
color: fires100,
mainAxisAlignment: MainAxisAlignment.center,
actions: <Widget>[new Flexible(child:
new Padding(
padding: new EdgeInsets.only(left: 10.0, right: 10.0), child:
new Column(
actions: <Widget>[
new Flexible(
child: new Padding(
padding: new EdgeInsets.only(left: 10.0, right: 10.0),
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
new Text(S
.of(context)
.mapPrivacy,
new Text(S.of(context).mapPrivacy,
style: new TextStyle(
fontStyle: FontStyle.italic, color: Colors.black38))
fontStyle: FontStyle.italic,
color: Colors.black38))
])))
]),
body: !(view.monitoredAreas is List)
@ -72,9 +69,7 @@ class MonitoredAreasPage extends StatelessWidget {
new Padding(
padding: new EdgeInsets.only(
top: 8.0, bottom: 8.0, left: 0.0, right: 0.0),
child: new Text(S
.of(context)
.inGreenMonitoredAreas),
child: new Text(S.of(context).inGreenMonitoredAreas),
),
new Flexible(
child: new FlutterMap(

View file

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

View file

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