From 188a9bc24938d713a7f3e2005c2e7414b6217302 Mon Sep 17 00:00:00 2001 From: vjrj Date: Sun, 10 Jun 2018 21:12:59 +0200 Subject: [PATCH] Polish and refactor --- lib/activeFires.dart | 82 +++++++++++-------------------------- lib/customBottomAppBar.dart | 16 ++++---- lib/leafletMap.dart | 8 ++-- lib/locationUtils.dart | 2 +- lib/mainDrawer.dart | 2 +- 5 files changed, 41 insertions(+), 69 deletions(-) diff --git a/lib/activeFires.dart b/lib/activeFires.dart index 6fd597f..a57a80f 100644 --- a/lib/activeFires.dart +++ b/lib/activeFires.dart @@ -11,8 +11,7 @@ import 'globals.dart' as globals; import 'basicLocationPersist.dart'; import 'package:http/http.dart' as http; import 'dart:convert' show json; -import 'customBottomAppBar.dart'; -import 'package:simple_moment/simple_moment.dart'; +import 'globalFiresBottomStats.dart'; import 'dart:convert'; class ActiveFiresPage extends StatefulWidget { @@ -26,8 +25,6 @@ class ActiveFiresPage extends StatefulWidget { class _ActiveFiresPageState extends State { final GlobalKey _scaffoldKey = new GlobalKey(); - String lastCheck; - int activeFires = 0; _ActiveFiresPageState(); @@ -137,30 +134,6 @@ class _ActiveFiresPageState extends State { }); } - @override - void initState() { - super.initState(); - http.read('${globals.firesApiUrl}status/last-fire-check').then((result) { - try { - var now = Moment.now(); - var last = DateTime.parse(json.decode(result)['value']); - setState(() { - lastCheck = now.from(last); - }); - } catch (e) { - print('Cannot get the last fire check'); - } - }); - http.read('${globals.firesApiUrl}status/active-fires-count').then((result) { - try { - int count = json.decode(result)['total']; - setState(() {activeFires = count;}); - } catch (e) { - print('Cannot get the last fire stats'); - } - }); - } - @override Widget build(BuildContext context) { print('Building Active Fires'); @@ -178,16 +151,8 @@ class _ActiveFiresPageState extends State { }, ), ), - bottomNavigationBar: new CustomBottomAppBar( - fabLocation: FloatingActionButtonLocation.centerDocked, - showNotch: true, - color: fires100, - actions: listWithoutNulls([ - activeFires > 0 && lastCheck != null ? - new Text('${activeFires} active fires worldwide. Updated ${lastCheck}'): - null, - SizedBox(width: 10.0) - ])), + floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, + bottomNavigationBar: new GlobalFiresBottomStats(), body: globals.yourLocations.length > 0 ? _buildSavedLocations() : new Center( @@ -207,25 +172,28 @@ class _ActiveFiresPageState extends State { backColor: fires600), ])), floatingActionButton: globals.yourLocations.length > 0 - ? Column(mainAxisAlignment: MainAxisAlignment.end, children: [ - FloatingActionButton.extended( - onPressed: onAddYourLocation, - heroTag: 'yourposition', - label: const Text('Add your position'), - icon: const Icon(Icons.location_searching), - ), - Padding( - padding: const EdgeInsets.only(top: 16.0), - child: FloatingActionButton.extended( - onPressed: () { - onAddOtherLocation(context); - }, - heroTag: 'otherplace', - label: new Text('Add some other place'), - icon: const Icon(Icons.edit_location), - ), - ) - ]) + ? Column( + mainAxisAlignment: MainAxisAlignment.end, + // crossAxisAlignment: CrossAxisAlignment.center, + children: [ + FloatingActionButton.extended( + onPressed: onAddYourLocation, + heroTag: 'yourposition', + label: const Text('Add your position'), + icon: const Icon(Icons.location_searching), + ), + Padding( + padding: const EdgeInsets.only(top: 16.0), + child: FloatingActionButton.extended( + onPressed: () { + onAddOtherLocation(context); + }, + heroTag: 'otherplace', + label: new Text('Add some other place'), + icon: const Icon(Icons.edit_location), + ), + ) + ]) : null, ); } diff --git a/lib/customBottomAppBar.dart b/lib/customBottomAppBar.dart index 5dfd661..d26a356 100644 --- a/lib/customBottomAppBar.dart +++ b/lib/customBottomAppBar.dart @@ -5,9 +5,11 @@ class CustomBottomAppBar extends StatelessWidget { {this.fabLocation, this.showNotch, this.color = Colors.black45, + this.mainAxisAlignment = MainAxisAlignment.center, this.actions}); final Color color; + final MainAxisAlignment mainAxisAlignment; final FloatingActionButtonLocation fabLocation; final bool showNotch; final List actions; @@ -20,14 +22,12 @@ class CustomBottomAppBar extends StatelessWidget { @override Widget build(BuildContext context) { - final List rowContents = [ - new SizedBox(height:56.0) - ]; + final List rowContents = [new SizedBox(height: 56.0)]; if (kCenterLocations.contains(fabLocation)) { - rowContents.add( + /* rowContents.add( const Expanded(child: const SizedBox()), - ); + ); */ } rowContents.addAll(this.actions); @@ -35,7 +35,9 @@ class CustomBottomAppBar extends StatelessWidget { return new BottomAppBar( color: color, hasNotch: showNotch, - child: new Row(children: rowContents), + child: new Row( + mainAxisAlignment: mainAxisAlignment, + children: rowContents), ); } -} \ No newline at end of file +} diff --git a/lib/leafletMap.dart b/lib/leafletMap.dart index a31c66f..d85c417 100644 --- a/lib/leafletMap.dart +++ b/lib/leafletMap.dart @@ -44,18 +44,20 @@ class _LeafletMapState extends State { appBar: new AppBar( title: new Text(title), ), - floatingActionButton: FloatingActionButton( + floatingActionButton: FloatingActionButton.extended( onPressed: () { }, - child: const Icon(Icons.notifications_none), - backgroundColor: Colors.orange, + icon: const Icon(Icons.notifications_none, color: fires600), + label: new Text('Subscribe', style: const TextStyle(color: fires600),), + backgroundColor: Colors.white, ), floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, bottomNavigationBar: new CustomBottomAppBar( fabLocation: FloatingActionButtonLocation.centerFloat, showNotch: false, color: fires100, + mainAxisAlignment: MainAxisAlignment.center, actions: listWithoutNulls([ numFires > 0 ? new Text('${numFires.toString()} fires at $kmAround ΠΊΠΌ around this area'): diff --git a/lib/locationUtils.dart b/lib/locationUtils.dart index ff1e2bd..373aada 100644 --- a/lib/locationUtils.dart +++ b/lib/locationUtils.dart @@ -9,7 +9,7 @@ Future getUserLocation(GlobalKey scaffoldKey) asyn try { Location _location = new Location(); Map location = await _location.getLocation; - print('location $location'); + // print('location $location'); // It seems that the lib fails with lat/lon values return new BasicLocation( diff --git a/lib/mainDrawer.dart b/lib/mainDrawer.dart index 9e2b8f3..486213b 100644 --- a/lib/mainDrawer.dart +++ b/lib/mainDrawer.dart @@ -66,7 +66,7 @@ Widget mainDrawer(BuildContext context) { ), new ListTile( leading: const Icon(Icons.location_on), - title: new Text('My areas'), + title: new Text('My subscribed areas'), onTap: () { // Then close the drawer Navigator.pushNamed(context, '/subscriptions');