fix: resolve 2 remaining strict analysis errors

- introPage.dart: Convert fireItems to proper static function closure
- mainDrawer.dart: Convert unreadCount int to String for Text widget
This commit is contained in:
vjrj 2026-03-06 11:21:06 +01:00
parent 1864e5b105
commit 7a4c9fb3bc
61 changed files with 1386 additions and 1202 deletions

View file

@ -1,14 +1,15 @@
import 'dart:async';
import 'package:fires_flutter/models/fireNotification.dart';
import 'package:fires_flutter/models/yourLocation.dart';
import 'package:flutter_map/src/layer/polyline_layer.dart';
import 'package:get_it/get_it.dart';
import 'package:objectid/objectid.dart';
import 'package:redux/redux.dart';
import '../models/appState.dart';
import '../models/fireNotification.dart';
import '../models/fireNotificationsPersist.dart';
import '../models/firesApi.dart';
import '../models/yourLocation.dart';
import '../models/yourLocationPersist.dart';
import '../objectIdUtils.dart';
import 'actions.dart';
@ -55,20 +56,20 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
if (action is AddYourLocationAction) {
if (action.loc.subscribed) {
subscribeViaApi(store, action.loc, (sub) {
store.dispatch(new AddedYourLocationAction(sub));
subscribeViaApi(store, action.loc, (YourLocation sub) {
store.dispatch(AddedYourLocationAction(sub));
persistYourLocations(store.state.yourLocations);
});
} else {
// No subscribed (only local)
store.dispatch(new AddedYourLocationAction(action.loc));
store.dispatch(AddedYourLocationAction(action.loc));
persistYourLocations(store.state.yourLocations);
}
getFiresStatsInLocation(store, action.loc);
}
if (action is DeleteYourLocationAction) {
store.dispatch(new DeletedYourLocationAction(action.loc.id));
store.dispatch(DeletedYourLocationAction(action.loc.id));
if (action.loc.subscribed) {
unsubsViaApi(store, action.loc.id, () {
persistYourLocations(store.state.yourLocations);
@ -79,17 +80,17 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
}
if (action is DeleteFireNotificationAction) {
store.dispatch(new DeletedFireNotificationAction(action.notif));
store.dispatch(DeletedFireNotificationAction(action.notif));
persistFireNotifications(store.state.fireNotifications);
}
if (action is DeleteAllFireNotificationAction) {
store.dispatch(new DeletedAllFireNotificationAction());
store.dispatch(DeletedAllFireNotificationAction());
persistFireNotifications(store.state.fireNotifications);
}
if (action is AddFireNotificationAction) {
store.dispatch(new AddedFireNotificationAction(action.notif));
store.dispatch(AddedFireNotificationAction(action.notif));
persistFireNotifications(store.state.fireNotifications);
}
@ -104,28 +105,28 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
if (action is UpdateYourLocationAction) {
if (action.loc.subscribed)
debounceLocationUpdate(
Duration(seconds: 2),
const Duration(seconds: 2),
() => api
.getFiresInLocation(
state: store.state,
lat: action.loc.lat,
lon: action.loc.lon,
distance: action.loc.distance)
.then((result) => store.dispatch(result)));
store.dispatch(new UpdatedYourLocationAction(action.loc));
.then((UpdateFireMapStatsAction result) => store.dispatch(result)));
store.dispatch(UpdatedYourLocationAction(action.loc));
persistYourLocations(store.state.yourLocations);
}
if (action is SubscribeConfirmAction) {
subscribeViaApi(store, action.loc, (sub) {
store.dispatch(new UpdateYourLocationAction(action.loc));
subscribeViaApi(store, action.loc, (YourLocation sub) {
store.dispatch(UpdateYourLocationAction(action.loc));
persistYourLocations(store.state.yourLocations);
});
}
if (action is UnSubscribeAction) {
unsubsViaApi(store, action.loc.id, () {
store.dispatch(new UpdateYourLocationAction(action.loc));
store.dispatch(UpdateYourLocationAction(action.loc));
persistYourLocations(store.state.yourLocations);
});
}
@ -133,21 +134,21 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
if (action is ToggleSubscriptionAction) {
if (action.loc.subscribed) {
subscribeViaApi(store, action.loc,
(sub) => store.dispatch(new ToggledSubscriptionAction(sub)));
(YourLocation sub) => store.dispatch(ToggledSubscriptionAction(sub)));
} else {
unsubsViaApi(store, action.loc.id,
() => store.dispatch(new ToggledSubscriptionAction(action.loc)));
() => store.dispatch(ToggledSubscriptionAction(action.loc)));
}
}
if (action is ReadFireNotificationAction) {
store.dispatch(new ReadedFireNotificationAction(action.notif));
store.dispatch(ReadedFireNotificationAction(action.notif));
persistFireNotifications(store.state.fireNotifications);
}
if (action is FetchYourLocationsAction) {
// Use the api to fetch the YourLocations
loadYourLocations().then((localLocations) {
loadYourLocations().then((List<YourLocation> localLocations) {
api
.fetchYourLocations(store.state)
.then((List<YourLocation> subscribedLocations) {
@ -155,61 +156,63 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
// Our reducer will then update the State using these YourLocations.
print('Subscribed to: ${subscribedLocations.length}');
// unsubscribe all locally to sync the subs state
localLocations.forEach((location) => location.subscribed = false);
for (final YourLocation location in localLocations) {
location.subscribed = false;
}
print('Local persisted: ${localLocations.length}');
subscribedLocations.forEach((subsLoc) {
var locSubs = localLocations.firstWhere(
(localLocation) => localLocation.id == subsLoc.id, orElse: () {
for (final YourLocation subsLoc in subscribedLocations) {
final YourLocation locSubs = localLocations.firstWhere(
(YourLocation localLocation) => localLocation.id == subsLoc.id, orElse: () {
localLocations.add(subsLoc);
return subsLoc;
});
locSubs.subscribed = true;
});
}
store.dispatch(new FetchYourLocationsSucceededAction(localLocations));
store.dispatch(FetchYourLocationsSucceededAction(localLocations));
persistYourLocations(localLocations);
localLocations.forEach((yl) {
for (final YourLocation yl in localLocations) {
api
.getFiresInLocation(
state: store.state,
lat: yl.lat,
lon: yl.lon,
distance: yl.distance)
.then((value) {
.then((UpdateFireMapStatsAction value) {
yl.currentNumFires = value.numFires;
store.dispatch(new UpdateYourLocationAction(yl));
store.dispatch(UpdateYourLocationAction(yl));
});
});
}
final Completer<Null>? completer = action.refreshCallback;
final Completer<void>? completer = action.refreshCallback;
completer?.complete(null);
});
}).catchError((Exception onError) {
// If it fails, dispatch a failure action. The reducer will
// update the state with the error.
store.dispatch(new FetchYourLocationsFailedAction(onError));
store.dispatch(FetchYourLocationsFailedAction(onError));
});
}
if (action is FetchFireNotificationsAction) {
loadFireNotifications().then((fireNotifications) {
loadFireNotifications().then((List<FireNotification> fireNotifications) {
int unread = 0;
for (FireNotification notif in fireNotifications) {
for (final FireNotification notif in fireNotifications) {
if (!notif.read) {
unread++;
}
}
store.dispatch(
new FetchFireNotificationsSucceededAction(fireNotifications, unread));
FetchFireNotificationsSucceededAction(fireNotifications, unread));
persistFireNotifications(fireNotifications);
});
}
if (action is FetchMonitoredAreasAction) {
api.getMonitoredAreas(state: store.state).then((result) {
api.getMonitoredAreas(state: store.state).then((List<Polyline> result) {
// store.dispatch()
store.dispatch(new FetchMonitoredAreasSucceededAction(result));
store.dispatch(FetchMonitoredAreasSucceededAction(result));
});
}
@ -217,11 +220,11 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
api
.markFalsePositive(store.state, store.state.user.token,
action.notif.sealed, action.type)
.then((result) {
.then((bool result) {
if (result) {
// Not necessary
getFiresStatsInFire(store, action.notif);
store.dispatch(new UpdatedFireNotificationAction(action.notif));
store.dispatch(UpdatedFireNotificationAction(action.notif));
}
});
}
@ -237,10 +240,10 @@ void getFiresStatsInLocation(Store<AppState> store, YourLocation loc) {
lat: loc.lat,
lon: loc.lon,
distance: loc.distance)
.then((result) {
.then((UpdateFireMapStatsAction result) {
store.dispatch(result);
loc.currentNumFires = result.numFires;
store.dispatch(new UpdateYourLocationAction(loc));
store.dispatch(UpdateYourLocationAction(loc));
});
}
@ -251,11 +254,11 @@ void getFiresStatsInFire(Store<AppState> store, FireNotification notif) {
lat: notif.lat,
lon: notif.lon,
distance: 1) // FalsePositive/server/publications.js
.then((result) => store.dispatch(result));
.then((UpdateFireMapStatsAction result) => store.dispatch(result));
}
void unsubsViaApi(Store<AppState> store, ObjectId id, onUnsubs) {
api.unsubscribe(store.state, id.hexString).then((res) {
api.unsubscribe(store.state, id.hexString).then((bool res) {
onUnsubs();
persistYourLocations(store.state.yourLocations);
});
@ -263,8 +266,8 @@ void unsubsViaApi(Store<AppState> store, ObjectId id, onUnsubs) {
void subscribeViaApi(
Store<AppState> store, YourLocation loc, Function(YourLocation) onSubs) {
api.subscribe(store.state, loc).then((subsId) {
YourLocation sub = loc;
api.subscribe(store.state, loc).then((String subsId) {
final YourLocation sub = loc;
// if (loc.id != subsId) {
sub.id = objectIdFromJson(subsId);
// }
@ -274,12 +277,12 @@ void subscribeViaApi(
}
void createUser(Store<AppState> store, String lang, String token) {
assert(token != null, "User lang is null");
assert(token != null, "User mobile token is null");
api.createUser(store.state, token, lang).then((userId) {
store.dispatch(new OnUserCreatedAction(userId));
store.dispatch(new FetchYourLocationsAction());
store.dispatch(new FetchFireNotificationsAction());
store.dispatch(new FetchMonitoredAreasAction());
assert(token != null, 'User lang is null');
assert(token != null, 'User mobile token is null');
api.createUser(store.state, token, lang).then((String userId) {
store.dispatch(OnUserCreatedAction(userId));
store.dispatch(FetchYourLocationsAction());
store.dispatch(FetchFireNotificationsAction());
store.dispatch(FetchMonitoredAreasAction());
});
}