diff --git a/lib/activeFires.dart b/lib/activeFires.dart index 941a5ad..46afa3d 100644 --- a/lib/activeFires.dart +++ b/lib/activeFires.dart @@ -203,7 +203,7 @@ class _ActiveFiresPageState extends State { return Scaffold( key: _scaffoldKey, // FIXME new? - drawer: MainDrawer.getDrawer(context), + drawer: new MainDrawer(context, ActiveFiresPage.routeName), appBar: new AppBar( title: Text(title), leading: IconButton( diff --git a/lib/fireAlert.dart b/lib/fireAlert.dart index 2601ff6..80e78c7 100644 --- a/lib/fireAlert.dart +++ b/lib/fireAlert.dart @@ -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 { 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, diff --git a/lib/fireNotificationList.dart b/lib/fireNotificationList.dart index a7c275e..1e248ad 100644 --- a/lib/fireNotificationList.dart +++ b/lib/fireNotificationList.dart @@ -178,7 +178,8 @@ class _FireNotificationListState extends State { return Scaffold( key: _scaffoldKey, - drawer: MainDrawer.getDrawer(context), + drawer: new MainDrawer(context, FireNotificationList.routeName), + appBar: new AppBar( title: Text(title), leading: IconButton( diff --git a/lib/homePage.dart b/lib/homePage.dart index 3b01789..cb848dc 100644 --- a/lib/homePage.dart +++ b/lib/homePage.dart @@ -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 { setState(() { store.dispatch(new OnConnectivityChanged(connectionStatus)); if (connectionStatus == ConnectivityResult.none) { - _showDialog(S - .of(context) - .noConnectivity); + _showDialog(S.of(context).noConnectivity); } }); } @@ -73,9 +72,9 @@ class _HomePageState extends State { _navigateToItemDetail(message); }); _firebaseMessaging.requestNotificationPermissions( - const IosNotificationSettings(sound: true, badge: true, alert: true)); + const IosNotificationSettings(sound: true, badge: true, alert: true)); _firebaseMessaging.onIosSettingsRegistered - .listen((IosNotificationSettings settings) { + .listen((IosNotificationSettings settings) { print("Settings registered: $settings"); }); _firebaseMessaging.getToken().then((String token) { @@ -85,15 +84,15 @@ class _HomePageState extends State { }); initConnectivity(); // StreamSubscription _connectivitySubscription = - _connectivity.onConnectivityChanged.listen((ConnectivityResult result) { - if (!mounted) { - return; - } - setState(() { - store.dispatch(new OnConnectivityChanged(result)); - // _showDialog(result.toString()); - }); + _connectivity.onConnectivityChanged.listen((ConnectivityResult result) { + if (!mounted) { + return; + } + setState(() { + store.dispatch(new OnConnectivityChanged(result)); + // _showDialog(result.toString()); }); + }); } final _homeFont = const TextStyle( @@ -101,25 +100,24 @@ class _HomePageState extends State { fontWeight: FontWeight.w600, // color: Colors.white, ); - final _btnFont = const TextStyle( + final _btnFont = const TextStyle( fontSize: 20.0, fontWeight: FontWeight.w600, // 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: [ FloatingActionButton.extended( elevation: 0.0, onPressed: () { - Navigator.pushNamed(context, ActiveFiresPage.routeName); + Navigator.pushNamed(context, ActiveFiresPage.routeName); }, label: Text(S.of(context).activeFires, style: _btnFont), backgroundColor: fires600, @@ -172,7 +170,6 @@ class _HomePageState extends State { child: new Text(S.of(context).appName, maxLines: 2, textAlign: TextAlign.center, - style: _homeFont), fit: BoxFit.scaleDown, )), @@ -182,22 +179,20 @@ class _HomePageState extends State { )); } - - void _showDialog(String message) { showDialog( - context: _scaffoldKey.currentContext, - builder: (_) => new AlertDialog( - content: new Text(message), - actions: [ - new FlatButton( - child: Text(S.of(_scaffoldKey.currentContext).CLOSE), - onPressed: () { - Navigator.pop(_scaffoldKey.currentContext); - }, - ), - ], - )); + context: _scaffoldKey.currentContext, + builder: (_) => new AlertDialog( + content: new Text(message), + actions: [ + new FlatButton( + child: Text(S.of(_scaffoldKey.currentContext).CLOSE), + onPressed: () { + Navigator.pop(_scaffoldKey.currentContext); + }, + ), + ], + )); } void _showItemDialog(Map message) { @@ -240,7 +235,8 @@ class _HomePageState extends State { /* 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- @@ -250,14 +246,14 @@ class _HomePageState extends State { FireNotification notif; try { notif = new FireNotification( - id: new ObjectId.fromHexString(message['id']), - subsId: new ObjectId.fromHexString(message['subsId']), - lat: double.parse(message['lat']), - lon: double.parse(message['lon']), - description: message['description'], - read: false, - when: DateTime.parse(message['when']), - sealed: message['sealed']); + id: new ObjectId.fromHexString(message['id']), + subsId: new ObjectId.fromHexString(message['subsId']), + lat: double.parse(message['lat']), + lon: double.parse(message['lon']), + description: message['description'], + read: false, + when: DateTime.parse(message['when']), + sealed: message['sealed']); debugPrint(notif.toString()); } catch (e) { debugPrint(e.toString()); @@ -265,5 +261,4 @@ class _HomePageState extends State { if (notif != null) store.dispatch(new AddFireNotificationAction(notif)); return notif; } - } diff --git a/lib/mainDrawer.dart b/lib/mainDrawer.dart index b2730cc..f4544b7 100644 --- a/lib/mainDrawer.dart +++ b/lib/mainDrawer.dart @@ -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(); - } catch (e) { - inj.map((i) => new MainDrawer(context), isSingleton: true); - d = inj.get(); - } - 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( 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), - title: new Text(S.of(context).monitoredAreasTitle), - onTap: () { - Navigator.pop(context); - Navigator.pushNamed(context, MonitoredAreasPage.routeName); - }, - ) - : null, + ? new ListTile( + leading: const Icon(Icons.map), + selected: currentRoute == MonitoredAreasPage.routeName, + title: new Text(S.of(context).monitoredAreasTitle), + onTap: () { + Navigator.pop(context); + 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: [ 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 ? diff --git a/lib/markdownPage.dart b/lib/markdownPage.dart index cb349c2..06df602 100644 --- a/lib/markdownPage.dart +++ b/lib/markdownPage.dart @@ -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 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 { final String title; + final String route; final Future 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 { }); return new Scaffold( appBar: new AppBar(title: new Text(title ?? '')), + drawer: new MainDrawer(context, route), body: new Markdown(data: pageData)); } } diff --git a/lib/monitoredAreas.dart b/lib/monitoredAreas.dart index 06305f8..83ce128 100644 --- a/lib/monitoredAreas.dart +++ b/lib/monitoredAreas.dart @@ -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'; @@ -18,10 +17,10 @@ class _ViewModel { @override bool operator ==(Object other) => - identical(this, other) || + identical(this, other) || other is _ViewModel && - runtimeType == other.runtimeType && - monitoredAreas == other.monitoredAreas; + runtimeType == other.runtimeType && + monitoredAreas == other.monitoredAreas; @override int get hashCode => monitoredAreas.hashCode; @@ -33,70 +32,66 @@ class MonitoredAreasPage extends StatelessWidget { @override Widget build(BuildContext context) { return new StoreConnector( - distinct: true, - converter: (store) { - return new _ViewModel(store.state.monitoredAreas); - }, - builder: (context, view) { - return new Scaffold( - appBar: - new AppBar(title: new Text(S - .of(context) - .monitoredAreasTitle)), - drawer: MainDrawer.getDrawer(context), - bottomNavigationBar: new CustomBottomAppBar( - fabLocation: FloatingActionButtonLocation.centerDocked, - showNotch: true, - color: fires100, - mainAxisAlignment: MainAxisAlignment.center, - actions: [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, - style: new TextStyle( - fontStyle: FontStyle.italic, color: Colors.black38)) - ]))) - ]), - body: !(view.monitoredAreas is List) - ? new SpinKitPulse(color: fires600) - : new Padding( - padding: new EdgeInsets.all(10.0), - child: new Column( - children: [ - 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), - ), - new Flexible( - child: new FlutterMap( - options: new MapOptions( - center: new LatLng(53.5775, 3.106111), - zoom: 1.0, + distinct: true, + converter: (store) { + return new _ViewModel(store.state.monitoredAreas); + }, + builder: (context, view) { + return new Scaffold( + appBar: + 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: [ + 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, + style: new TextStyle( + fontStyle: FontStyle.italic, + color: Colors.black38)) + ]))) + ]), + body: !(view.monitoredAreas is List) + ? new SpinKitPulse(color: fires600) + : new Padding( + padding: new EdgeInsets.all(10.0), + child: new Column( + children: [ + 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), + ), + new Flexible( + child: new FlutterMap( + options: new MapOptions( + center: new LatLng(53.5775, 3.106111), + zoom: 1.0, + ), + layers: [ + new TileLayerOptions( + urlTemplate: + "https://tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png", + subdomains: ['a', 'b', 'c']), + new PolylineLayerOptions( + polylines: view.monitoredAreas, + ) + ], + ), + ), + ], ), - layers: [ - new TileLayerOptions( - urlTemplate: - "https://tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png", - subdomains: ['a', 'b', 'c']), - new PolylineLayerOptions( - polylines: view.monitoredAreas, - ) - ], ), - ), - ], - ), - ), - ); - }); + ); + }); } } diff --git a/lib/privacyPage.dart b/lib/privacyPage.dart index f787415..e77b47a 100644 --- a/lib/privacyPage.dart +++ b/lib/privacyPage.dart @@ -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', diff --git a/lib/supportPage.dart b/lib/supportPage.dart index 05be94e..a7d239f 100644 --- a/lib/supportPage.dart +++ b/lib/supportPage.dart @@ -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 { 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: [ new Flexible( child: new CenteredColumn(children: [ - new Text(S.of(context).supportPageDescription, textAlign: TextAlign.center,), + new Text( + S.of(context).supportPageDescription, + textAlign: TextAlign.center, + ), new SizedBox(height: 20.0), buildSupportButton() ]))