- Type dynamic map accesses properly (avoid_dynamic_calls in genericMap, globalFiresBottomStats) - Capture context before async gaps (use_build_context_synchronously in genericMap, genericMapBottom, globalFiresBottomStats) - Replace print() with debugPrint() (avoid_print in firesApi.dart) - Rename fireMarker function and _LayerSelectorButton to camelCase - Rename variable FireNotifications to fireNotifications - Fix no_default_cases in switch statements (add missing subscriptionConfirm case) - Make FireNotification fields final, remove @immutable from YourLocation (mutable) - Make monitoredAreas field final in _ViewModel - Update subscribeViaApi to use copyWith instead of direct field assignment
76 lines
2.3 KiB
Dart
76 lines
2.3 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 dynamic decodedResult = json.decode(result);
|
|
final Map<String, dynamic> resultMap =
|
|
decodedResult as Map<String, dynamic>;
|
|
final DateTime last = DateTime.parse(resultMap['value'] as String);
|
|
http
|
|
.read(Uri.parse('${firesApiUrl}status/active-fires-count'))
|
|
.then((String result) {
|
|
try {
|
|
final dynamic decodedCountResult = json.decode(result);
|
|
final Map<String, dynamic> countMap =
|
|
decodedCountResult as Map<String, dynamic>;
|
|
final int count = (countMap['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);
|
|
}
|
|
}
|