- Fix deprecated @ignore in json_serializable models (appState, yourLocation) - Fix empty catch blocks in compassMapPlugin, globalFiresBottomStats, locationUtils - Fix no_logic_in_create_state in firesApp, markdownPage, slider - Fix use_build_context_synchronously in fireAlert - Fix only_throw_errors in firesApi (8 instances) - Exclude generated .g.dart files from analysis - Update deprecated nullable: false to @JsonSerializable() Build: APK generated successfully, 0 errors, 0 warnings
71 lines
2 KiB
Dart
71 lines
2 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'colors.dart';
|
|
import 'customBottomAppBar.dart';
|
|
import 'customMoment.dart';
|
|
import 'generated/i18n.dart';
|
|
|
|
class GlobalFiresBottomStats extends StatefulWidget {
|
|
const GlobalFiresBottomStats({super.key});
|
|
|
|
@override
|
|
_GlobalFiresBottomStatsState createState() => _GlobalFiresBottomStatsState();
|
|
}
|
|
|
|
class _GlobalFiresBottomStatsState extends State<GlobalFiresBottomStats> {
|
|
late String lastCheck;
|
|
int activeFires = 0;
|
|
final String firesApiUrl =
|
|
GetIt.instance<String>(instanceName: 'firesApiUrl');
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
http
|
|
.read(Uri.parse('${firesApiUrl}status/last-fire-check'))
|
|
.then((String result) {
|
|
try {
|
|
final Moment now = Moment.now();
|
|
final DateTime last =
|
|
DateTime.parse(json.decode(result)['value'] as String);
|
|
http
|
|
.read(Uri.parse('${firesApiUrl}status/active-fires-count'))
|
|
.then((String result) {
|
|
try {
|
|
final int count = (json.decode(result)['total'] as num).toInt();
|
|
setState(() {
|
|
lastCheck = now.from(context, last);
|
|
activeFires = count;
|
|
});
|
|
} catch (_) {
|
|
// Ignore JSON parse errors
|
|
}
|
|
});
|
|
} catch (_) {
|
|
// Ignore storage read errors
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final List<Widget> actionWidgets = <Widget>[];
|
|
if (activeFires > 0) {
|
|
actionWidgets
|
|
.add(Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
|
Text(S.of(context).activeFiresWorldWide(activeFires.toString())),
|
|
Text(S.of(context).updatedLastCheck(lastCheck))
|
|
]));
|
|
}
|
|
|
|
return CustomBottomAppBar(
|
|
fabLocation: FloatingActionButtonLocation.centerDocked,
|
|
showNotch: true,
|
|
color: fires100,
|
|
actions: actionWidgets);
|
|
}
|
|
}
|