Polish and refactor
This commit is contained in:
parent
5bea196253
commit
40842dc4e4
1 changed files with 65 additions and 0 deletions
65
lib/globalFiresBottomStats.dart
Normal file
65
lib/globalFiresBottomStats.dart
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:simple_moment/simple_moment.dart';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'globals.dart' as globals;
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||||
|
import 'customBottomAppBar.dart';
|
||||||
|
import 'colors.dart';
|
||||||
|
|
||||||
|
class GlobalFiresBottomStats extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_GlobalFiresBottomStatsState createState() => _GlobalFiresBottomStatsState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _GlobalFiresBottomStatsState extends State<GlobalFiresBottomStats> {
|
||||||
|
String lastCheck;
|
||||||
|
int activeFires = 0;
|
||||||
|
|
||||||
|
@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) {
|
||||||
|
return new CustomBottomAppBar(
|
||||||
|
fabLocation: FloatingActionButtonLocation.centerDocked,
|
||||||
|
showNotch: true,
|
||||||
|
color: fires100,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
actions: listWithoutNulls(<Widget>[
|
||||||
|
activeFires > 0 && lastCheck != null
|
||||||
|
? new Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
new Text('${activeFires} active fires worldwide'),
|
||||||
|
new Text('Updated ${lastCheck}')
|
||||||
|
])
|
||||||
|
: null,
|
||||||
|
SizedBox(width: 10.0)
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue