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 '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<ActiveFiresPage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
String lastCheck;
int activeFires = 0;
_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
Widget build(BuildContext context) {
print('Building Active Fires');
@ -178,16 +151,8 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
},
),
),
bottomNavigationBar: new CustomBottomAppBar(
fabLocation: FloatingActionButtonLocation.centerDocked,
showNotch: true,
color: fires100,
actions: listWithoutNulls(<Widget>[
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<ActiveFiresPage> {
backColor: fires600),
])),
floatingActionButton: globals.yourLocations.length > 0
? Column(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
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: <Widget>[
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,
);
}

View file

@ -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<Widget> actions;
@ -20,14 +22,12 @@ class CustomBottomAppBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final List<Widget> rowContents = <Widget>[
new SizedBox(height:56.0)
];
final List<Widget> rowContents = <Widget>[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),
);
}
}
}

View file

@ -44,18 +44,20 @@ class _LeafletMapState extends State<LeafletMap> {
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(<Widget>[
numFires > 0 ?
new Text('${numFires.toString()} fires at $kmAround км around this area'):

View file

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

View file

@ -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');