Remove info-level lint issues: avoid_dynamic_calls, use_build_context_synchronously, avoid_print, non_constant_identifier_names

- 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
This commit is contained in:
vjrj 2026-03-11 16:53:48 +01:00
parent 82cf8fc7cc
commit 270d9a569e
12 changed files with 72 additions and 61 deletions

File diff suppressed because one or more lines are too long

View file

@ -6,7 +6,7 @@ import 'fireMarkType.dart';
import 'fireMarkerIcon.dart'; import 'fireMarkerIcon.dart';
/// Create a Marker with custom positioning for fires and other map objects /// Create a Marker with custom positioning for fires and other map objects
Marker FireMarker( Marker fireMarker(
LatLng pos, LatLng pos,
FireMarkType type, [ FireMarkType type, [
VoidCallback? onTap, VoidCallback? onTap,

View file

@ -364,6 +364,7 @@ class GenericMapState extends State<GenericMap> {
switch (status) { switch (status) {
case FireMapStatus.view: case FireMapStatus.view:
case FireMapStatus.unsubscribe: case FireMapStatus.unsubscribe:
case FireMapStatus.subscriptionConfirm:
return <Widget>[ return <Widget>[
IconButton( IconButton(
icon: const Icon(Icons.edit), icon: const Icon(Icons.edit),
@ -384,8 +385,6 @@ class GenericMapState extends State<GenericMap> {
'${view.mapState.fireNotification?.description ?? 'Fire'}. ${view.serverUrl}fire/${view.mapState.fireNotification?.sealed ?? ''}'); '${view.mapState.fireNotification?.description ?? 'Fire'}. ${view.serverUrl}fire/${view.mapState.fireNotification?.sealed ?? ''}');
}) })
]; ];
default:
return <Widget>[];
} }
} }
@ -409,10 +408,10 @@ class GenericMapState extends State<GenericMap> {
// print('false pos: ${coords}'); // print('false pos: ${coords}');
final LatLng loc = LatLng( final LatLng loc = LatLng(
(coords[1] as num).toDouble(), (coords[0] as num).toDouble()); (coords[1] as num).toDouble(), (coords[0] as num).toDouble());
markers.add(FireMarker(loc, FireMarkType.falsePos, () { markers.add(fireMarker(loc, FireMarkType.falsePos, () {
_showFalsePositiveDialog(loc); _showFalsePositiveDialog(loc);
})); }));
// if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel)); // if (calibrate) markers.add(fireMarker(loc, FireMarkType.pixel));
} catch (e, stackTrace) { } catch (e, stackTrace) {
reportError(e, stackTrace); reportError(e, stackTrace);
} }
@ -420,55 +419,62 @@ class GenericMapState extends State<GenericMap> {
for (final dynamic industry in industries) { for (final dynamic industry in industries) {
try { try {
// print(fire['geo']['coordinates']); // print(fire['geo']['coordinates']);
final List<dynamic> coords = final Map<String, dynamic> industryMap =
industry['geo']['coordinates'] as List<dynamic>; industry as Map<String, dynamic>;
final dynamic geoData = industryMap['geo'];
final Map<String, dynamic> geo = geoData as Map<String, dynamic>;
final List<dynamic> coords = geo['coordinates'] as List<dynamic>;
final LatLng loc = LatLng( final LatLng loc = LatLng(
(coords[1] as num).toDouble(), (coords[0] as num).toDouble()); (coords[1] as num).toDouble(), (coords[0] as num).toDouble());
markers.add(FireMarker(loc, FireMarkType.industry, () { markers.add(fireMarker(loc, FireMarkType.industry, () {
_showIndustryDialog(loc); _showIndustryDialog(loc);
})); }));
// if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel)); // if (calibrate) markers.add(fireMarker(loc, FireMarkType.pixel));
} catch (e, stackTrace) { } catch (e, stackTrace) {
reportError(e, stackTrace); reportError(e, stackTrace);
} }
} }
for (final dynamic fire in fires) { for (final dynamic fire in fires) {
try { try {
final LatLng loc = LatLng( final Map<String, dynamic> fireMap = fire as Map<String, dynamic>;
(fire['lat'] as num).toDouble(), (fire['lon'] as num).toDouble()); final dynamic lat = fireMap['lat'];
markers.add(FireMarker(loc, FireMarkType.fire, () { final dynamic lon = fireMap['lon'];
onFirePressed(loc, DateTime.parse(fire['when'].toString()), final dynamic when = fireMap['when'];
fire['type'] as String); final dynamic type = fireMap['type'];
final LatLng loc =
LatLng((lat as num).toDouble(), (lon as num).toDouble());
markers.add(fireMarker(loc, FireMarkType.fire, () {
onFirePressed(loc, DateTime.parse(when.toString()), type as String);
})); }));
markers.add(FireMarker(loc, FireMarkType.pixel)); markers.add(fireMarker(loc, FireMarkType.pixel));
} catch (e, stackTrace) { } catch (e, stackTrace) {
reportError(e, stackTrace); reportError(e, stackTrace);
} }
} }
markers.add( markers.add(
FireMarker(pos, isNotif ? FireMarkType.fire : FireMarkType.position)); fireMarker(pos, isNotif ? FireMarkType.fire : FireMarkType.position));
// if (calibrate) markers.add(FireMarker(pos, FireMarkType.pixel)); // if (calibrate) markers.add(fireMarker(pos, FireMarkType.pixel));
return markers; return markers;
} }
void _showFireDialog(LatLng pos, DateTime date, String type) { void _showFireDialog(LatLng pos, DateTime date, String type) {
final String when = Moment.fromDate(date).fromNow(context); final String when = Moment.fromDate(date).fromNow(context);
final S strings = S.of(context);
final String by =
type == 'vecinal' ? strings.byOurUsers : strings.byNASAsatellites;
getReverseLocation(lat: pos.latitude, lon: pos.longitude) getReverseLocation(lat: pos.latitude, lon: pos.longitude)
.then((String reverseLoc) { .then((String reverseLoc) {
final String by = type == 'vecinal'
? S.of(context).byOurUsers
: S.of(context).byNASAsatellites;
final String fireDesc = final String fireDesc =
S.of(context).additionalInfoAboutFire(reverseLoc, when, by); strings.additionalInfoAboutFire(reverseLoc, when, by);
showDialog<bool>( showDialog<bool>(
context: _scaffoldKey.currentContext!, context: _scaffoldKey.currentContext!,
builder: (_) => AlertDialog( builder: (_) => AlertDialog(
content: Text(fireDesc), content: Text(fireDesc),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context).CLOSE), child: Text(strings.CLOSE),
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(_scaffoldKey.currentContext!);
}, },
), ),
], ],
@ -477,21 +483,22 @@ class GenericMapState extends State<GenericMap> {
} }
void _showIndustryDialog(LatLng pos) { void _showIndustryDialog(LatLng pos) {
final S strings = S.of(context);
getReverseLocation(lat: pos.latitude, lon: pos.longitude) getReverseLocation(lat: pos.latitude, lon: pos.longitude)
.then((String reverseLoc) { .then((String reverseLoc) {
final String industryDesc = '${S.of(context).itSeemsAIndustry}\n\n' final String industryDesc = '${strings.itSeemsAIndustry}\n\n'
'Type: Industry\n' 'Type: Industry\n'
'Location: $reverseLoc'; 'Location: $reverseLoc';
showDialog<bool>( showDialog<bool>(
context: _scaffoldKey.currentContext!, context: _scaffoldKey.currentContext!,
builder: (_) => AlertDialog( builder: (_) => AlertDialog(
title: Text(S.of(context).notAWildfire), title: Text(strings.notAWildfire),
content: Text(industryDesc), content: Text(industryDesc),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context).CLOSE), child: Text(strings.CLOSE),
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(_scaffoldKey.currentContext!);
}, },
), ),
], ],
@ -500,21 +507,22 @@ class GenericMapState extends State<GenericMap> {
} }
void _showFalsePositiveDialog(LatLng pos) { void _showFalsePositiveDialog(LatLng pos) {
final S strings = S.of(context);
getReverseLocation(lat: pos.latitude, lon: pos.longitude) getReverseLocation(lat: pos.latitude, lon: pos.longitude)
.then((String reverseLoc) { .then((String reverseLoc) {
final String falseDesc = '${S.of(context).itSeemsNotAtForesFire}\n\n' final String falseDesc = '${strings.itSeemsNotAtForesFire}\n\n'
'Type: False Positive\n' 'Type: False Positive\n'
'Location: $reverseLoc'; 'Location: $reverseLoc';
showDialog<bool>( showDialog<bool>(
context: _scaffoldKey.currentContext!, context: _scaffoldKey.currentContext!,
builder: (_) => AlertDialog( builder: (_) => AlertDialog(
title: Text(S.of(context).notAWildfire), title: Text(strings.notAWildfire),
content: Text(falseDesc), content: Text(falseDesc),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context).CLOSE), child: Text(strings.CLOSE),
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(_scaffoldKey.currentContext!);
}, },
), ),
], ],

View file

@ -112,17 +112,20 @@ class GenericMapBottom extends StatelessWidget {
return DropdownMenuItem<FalsePositiveType>( return DropdownMenuItem<FalsePositiveType>(
value: value, child: Text(menuText)); value: value, child: Text(menuText));
}).toList(), }).toList(),
onChanged: (FalsePositiveType? value) async { onChanged: (FalsePositiveType? value) {
final S strings = S.of(context);
final ScaffoldMessengerState messenger =
ScaffoldMessenger.of(context);
if (value != null) { if (value != null) {
onFalsePositive(notif, value); onFalsePositive(notif, value);
} }
await Future<void>.delayed( Future<void>.delayed(
const Duration(milliseconds: 500)); const Duration(milliseconds: 500))
ScaffoldMessenger.of(context) .then((_) {
.showSnackBar(SnackBar( messenger.showSnackBar(SnackBar(
content: content: Text(strings.thanksForParticipating),
Text(S.of(context).thanksForParticipating),
)); ));
});
}), }),
] as List<Widget>))))); ] as List<Widget>)))));
} }

View file

@ -30,13 +30,18 @@ class _GlobalFiresBottomStatsState extends State<GlobalFiresBottomStats> {
.then((String result) { .then((String result) {
try { try {
final Moment now = Moment.now(); final Moment now = Moment.now();
final DateTime last = final dynamic decodedResult = json.decode(result);
DateTime.parse(json.decode(result)['value'] as String); final Map<String, dynamic> resultMap =
decodedResult as Map<String, dynamic>;
final DateTime last = DateTime.parse(resultMap['value'] as String);
http http
.read(Uri.parse('${firesApiUrl}status/active-fires-count')) .read(Uri.parse('${firesApiUrl}status/active-fires-count'))
.then((String result) { .then((String result) {
try { try {
final int count = (json.decode(result)['total'] as num).toInt(); 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(() { setState(() {
lastCheck = now.from(context, last); lastCheck = now.from(context, last);
activeFires = count; activeFires = count;

View file

@ -22,7 +22,7 @@ class LayerSelectorMapPluginWidget extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Column( Column(
children: <Widget>[_LayerSelectorButton(store)], children: <Widget>[_layerSelectorButton(store)],
) )
], ],
), ),
@ -30,7 +30,7 @@ class LayerSelectorMapPluginWidget extends StatelessWidget {
])); ]));
} }
Widget _LayerSelectorButton(Store<AppState> store) { Widget _layerSelectorButton(Store<AppState> store) {
final GlobalKey<PopupMenuButtonState<FireMapLayer>> key = final GlobalKey<PopupMenuButtonState<FireMapLayer>> key =
GlobalKey<PopupMenuButtonState<FireMapLayer>>(); GlobalKey<PopupMenuButtonState<FireMapLayer>>();

View file

@ -23,7 +23,7 @@ class FireNotification {
factory FireNotification.fromJson(Map<String, dynamic> json) => factory FireNotification.fromJson(Map<String, dynamic> json) =>
_$FireNotificationFromJson(json); _$FireNotificationFromJson(json);
@JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson) @JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson)
ObjectId id; final ObjectId id;
final double lat; final double lat;
final double lon; final double lon;
final String description; final String description;

View file

@ -10,10 +10,10 @@ const String fireNotificationKey = 'fireNotifications';
Future<List<FireNotification>> loadFireNotifications() async { Future<List<FireNotification>> loadFireNotifications() async {
return globals.prefs.then((SharedPreferences prefs) { return globals.prefs.then((SharedPreferences prefs) {
final List<String>? FireNotifications = final List<String>? fireNotifications =
prefs.getStringList(fireNotificationKey); prefs.getStringList(fireNotificationKey);
final List<FireNotification> persistedList = <FireNotification>[]; final List<FireNotification> persistedList = <FireNotification>[];
for (final String notificationString in (FireNotifications ?? <String>[])) { for (final String notificationString in (fireNotifications ?? <String>[])) {
final Map<String, dynamic> notificationMap = final Map<String, dynamic> notificationMap =
json.decode(notificationString) as Map<String, dynamic>; json.decode(notificationString) as Map<String, dynamic>;
persistedList.add(FireNotification.fromJson(notificationMap)); persistedList.add(FireNotification.fromJson(notificationMap));

View file

@ -133,7 +133,7 @@ class FiresApi {
final String url = final String url =
'${state.firesApiUrl}fires-in-full/${state.firesApiKey}/$lat/$lon/$distance'; '${state.firesApiUrl}fires-in-full/${state.firesApiKey}/$lat/$lon/$distance';
if (globals.isDevelopment) { if (globals.isDevelopment) {
print(url); debugPrint(url);
} }
try { try {
final Response<dynamic> response = await _dio.get(url); final Response<dynamic> response = await _dio.get(url);
@ -218,7 +218,7 @@ class FiresApi {
response.data as Map<String, dynamic>; response.data as Map<String, dynamic>;
final Map<String, dynamic> dataData = final Map<String, dynamic> dataData =
data['data'] as Map<String, dynamic>; data['data'] as Map<String, dynamic>;
print(dataData['upsert']); debugPrint(dataData['upsert'].toString());
} }
return true; return true;
} else { } else {

View file

@ -6,7 +6,6 @@ import '../objectIdUtils.dart';
part 'yourLocation.g.dart'; part 'yourLocation.g.dart';
@immutable
@JsonSerializable() @JsonSerializable()
class YourLocation { class YourLocation {
YourLocation( YourLocation(
@ -16,20 +15,19 @@ class YourLocation {
this.description = '', this.description = '',
this.distance = 10, this.distance = 10,
int? currentNumFires, int? currentNumFires,
this.subscribed = false}) { this.subscribed = false})
this.currentNumFires = currentNumFires ?? 0; : currentNumFires = currentNumFires ?? 0;
}
factory YourLocation.fromJson(Map<String, dynamic> json) => factory YourLocation.fromJson(Map<String, dynamic> json) =>
_$YourLocationFromJson(json); _$YourLocationFromJson(json);
@JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson) @JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson)
ObjectId id; final ObjectId id;
final double lat; final double lat;
final double lon; final double lon;
String description; String description;
bool subscribed; bool subscribed;
int distance; int distance;
late int currentNumFires; int currentNumFires;
static YourLocation get noLocation { static YourLocation get noLocation {
_noLocation ??= YourLocation(id: ObjectId(), lat: 0.0, lon: 0.0); _noLocation ??= YourLocation(id: ObjectId(), lat: 0.0, lon: 0.0);

View file

@ -14,7 +14,7 @@ import 'models/appState.dart';
@immutable @immutable
class _ViewModel { class _ViewModel {
_ViewModel(this.monitoredAreas); _ViewModel(this.monitoredAreas);
List<Polyline> monitoredAreas; final List<Polyline> monitoredAreas;
@override @override
bool operator ==(Object other) => bool operator ==(Object other) =>

View file

@ -269,10 +269,7 @@ void unsubsViaApi(
void subscribeViaApi(Store<AppState> store, YourLocation loc, void subscribeViaApi(Store<AppState> store, YourLocation loc,
void Function(YourLocation) onSubs) { void Function(YourLocation) onSubs) {
api.subscribe(store.state, loc).then((String subsId) { api.subscribe(store.state, loc).then((String subsId) {
final YourLocation sub = loc; final YourLocation sub = loc.copyWith(id: objectIdFromJson(subsId));
// if (loc.id != subsId) {
sub.id = objectIdFromJson(subsId);
// }
onSubs(sub); onSubs(sub);
persistYourLocations(store.state.yourLocations); persistYourLocations(store.state.yourLocations);
}); });