Polish and refactor

This commit is contained in:
vjrj 2018-06-10 21:12:59 +02:00
parent 40842dc4e4
commit 188a9bc249
5 changed files with 41 additions and 69 deletions

View file

@ -11,8 +11,7 @@ import 'globals.dart' as globals;
import 'basicLocationPersist.dart'; import 'basicLocationPersist.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'dart:convert' show json; import 'dart:convert' show json;
import 'customBottomAppBar.dart'; import 'globalFiresBottomStats.dart';
import 'package:simple_moment/simple_moment.dart';
import 'dart:convert'; import 'dart:convert';
class ActiveFiresPage extends StatefulWidget { class ActiveFiresPage extends StatefulWidget {
@ -26,8 +25,6 @@ class ActiveFiresPage extends StatefulWidget {
class _ActiveFiresPageState extends State<ActiveFiresPage> { class _ActiveFiresPageState extends State<ActiveFiresPage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
String lastCheck;
int activeFires = 0;
_ActiveFiresPageState(); _ActiveFiresPageState();
@ -137,30 +134,6 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
}); });
} }
@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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print('Building Active Fires'); print('Building Active Fires');
@ -178,16 +151,8 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
}, },
), ),
), ),
bottomNavigationBar: new CustomBottomAppBar( floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
fabLocation: FloatingActionButtonLocation.centerDocked, bottomNavigationBar: new GlobalFiresBottomStats(),
showNotch: true,
color: fires100,
actions: listWithoutNulls(<Widget>[
activeFires > 0 && lastCheck != null ?
new Text('${activeFires} active fires worldwide. Updated ${lastCheck}'):
null,
SizedBox(width: 10.0)
])),
body: globals.yourLocations.length > 0 body: globals.yourLocations.length > 0
? _buildSavedLocations() ? _buildSavedLocations()
: new Center( : new Center(
@ -207,25 +172,28 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
backColor: fires600), backColor: fires600),
])), ])),
floatingActionButton: globals.yourLocations.length > 0 floatingActionButton: globals.yourLocations.length > 0
? Column(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[ ? Column(
FloatingActionButton.extended( mainAxisAlignment: MainAxisAlignment.end,
onPressed: onAddYourLocation, // crossAxisAlignment: CrossAxisAlignment.center,
heroTag: 'yourposition', children: <Widget>[
label: const Text('Add your position'), FloatingActionButton.extended(
icon: const Icon(Icons.location_searching), onPressed: onAddYourLocation,
), heroTag: 'yourposition',
Padding( label: const Text('Add your position'),
padding: const EdgeInsets.only(top: 16.0), icon: const Icon(Icons.location_searching),
child: FloatingActionButton.extended( ),
onPressed: () { Padding(
onAddOtherLocation(context); padding: const EdgeInsets.only(top: 16.0),
}, child: FloatingActionButton.extended(
heroTag: 'otherplace', onPressed: () {
label: new Text('Add some other place'), onAddOtherLocation(context);
icon: const Icon(Icons.edit_location), },
), heroTag: 'otherplace',
) label: new Text('Add some other place'),
]) icon: const Icon(Icons.edit_location),
),
)
])
: null, : null,
); );
} }

View file

@ -5,9 +5,11 @@ class CustomBottomAppBar extends StatelessWidget {
{this.fabLocation, {this.fabLocation,
this.showNotch, this.showNotch,
this.color = Colors.black45, this.color = Colors.black45,
this.mainAxisAlignment = MainAxisAlignment.center,
this.actions}); this.actions});
final Color color; final Color color;
final MainAxisAlignment mainAxisAlignment;
final FloatingActionButtonLocation fabLocation; final FloatingActionButtonLocation fabLocation;
final bool showNotch; final bool showNotch;
final List<Widget> actions; final List<Widget> actions;
@ -20,14 +22,12 @@ class CustomBottomAppBar extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final List<Widget> rowContents = <Widget>[ final List<Widget> rowContents = <Widget>[new SizedBox(height: 56.0)];
new SizedBox(height:56.0)
];
if (kCenterLocations.contains(fabLocation)) { if (kCenterLocations.contains(fabLocation)) {
rowContents.add( /* rowContents.add(
const Expanded(child: const SizedBox()), const Expanded(child: const SizedBox()),
); ); */
} }
rowContents.addAll(this.actions); rowContents.addAll(this.actions);
@ -35,7 +35,9 @@ class CustomBottomAppBar extends StatelessWidget {
return new BottomAppBar( return new BottomAppBar(
color: color, color: color,
hasNotch: showNotch, hasNotch: showNotch,
child: new Row(children: rowContents), child: new Row(
mainAxisAlignment: mainAxisAlignment,
children: rowContents),
); );
} }
} }

View file

@ -44,18 +44,20 @@ class _LeafletMapState extends State<LeafletMap> {
appBar: new AppBar( appBar: new AppBar(
title: new Text(title), title: new Text(title),
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton.extended(
onPressed: () { onPressed: () {
}, },
child: const Icon(Icons.notifications_none), icon: const Icon(Icons.notifications_none, color: fires600),
backgroundColor: Colors.orange, label: new Text('Subscribe', style: const TextStyle(color: fires600),),
backgroundColor: Colors.white,
), ),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
bottomNavigationBar: new CustomBottomAppBar( bottomNavigationBar: new CustomBottomAppBar(
fabLocation: FloatingActionButtonLocation.centerFloat, fabLocation: FloatingActionButtonLocation.centerFloat,
showNotch: false, showNotch: false,
color: fires100, color: fires100,
mainAxisAlignment: MainAxisAlignment.center,
actions: listWithoutNulls(<Widget>[ actions: listWithoutNulls(<Widget>[
numFires > 0 ? numFires > 0 ?
new Text('${numFires.toString()} fires at $kmAround км around this area'): new Text('${numFires.toString()} fires at $kmAround км around this area'):

View file

@ -9,7 +9,7 @@ Future<BasicLocation> getUserLocation(GlobalKey<ScaffoldState> scaffoldKey) asyn
try { try {
Location _location = new Location(); Location _location = new Location();
Map<String, double> location = await _location.getLocation; Map<String, double> location = await _location.getLocation;
print('location $location'); // print('location $location');
// It seems that the lib fails with lat/lon values // It seems that the lib fails with lat/lon values
return new BasicLocation( return new BasicLocation(

View file

@ -66,7 +66,7 @@ Widget mainDrawer(BuildContext context) {
), ),
new ListTile( new ListTile(
leading: const Icon(Icons.location_on), leading: const Icon(Icons.location_on),
title: new Text('My areas'), title: new Text('My subscribed areas'),
onTap: () { onTap: () {
// Then close the drawer // Then close the drawer
Navigator.pushNamed(context, '/subscriptions'); Navigator.pushNamed(context, '/subscriptions');