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:
parent
82cf8fc7cc
commit
270d9a569e
12 changed files with 72 additions and 61 deletions
File diff suppressed because one or more lines are too long
|
|
@ -6,7 +6,7 @@ import 'fireMarkType.dart';
|
|||
import 'fireMarkerIcon.dart';
|
||||
|
||||
/// Create a Marker with custom positioning for fires and other map objects
|
||||
Marker FireMarker(
|
||||
Marker fireMarker(
|
||||
LatLng pos,
|
||||
FireMarkType type, [
|
||||
VoidCallback? onTap,
|
||||
|
|
|
|||
|
|
@ -364,6 +364,7 @@ class GenericMapState extends State<GenericMap> {
|
|||
switch (status) {
|
||||
case FireMapStatus.view:
|
||||
case FireMapStatus.unsubscribe:
|
||||
case FireMapStatus.subscriptionConfirm:
|
||||
return <Widget>[
|
||||
IconButton(
|
||||
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 ?? ''}');
|
||||
})
|
||||
];
|
||||
default:
|
||||
return <Widget>[];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -409,10 +408,10 @@ class GenericMapState extends State<GenericMap> {
|
|||
// print('false pos: ${coords}');
|
||||
final LatLng loc = LatLng(
|
||||
(coords[1] as num).toDouble(), (coords[0] as num).toDouble());
|
||||
markers.add(FireMarker(loc, FireMarkType.falsePos, () {
|
||||
markers.add(fireMarker(loc, FireMarkType.falsePos, () {
|
||||
_showFalsePositiveDialog(loc);
|
||||
}));
|
||||
// if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel));
|
||||
// if (calibrate) markers.add(fireMarker(loc, FireMarkType.pixel));
|
||||
} catch (e, stackTrace) {
|
||||
reportError(e, stackTrace);
|
||||
}
|
||||
|
|
@ -420,55 +419,62 @@ class GenericMapState extends State<GenericMap> {
|
|||
for (final dynamic industry in industries) {
|
||||
try {
|
||||
// print(fire['geo']['coordinates']);
|
||||
final List<dynamic> coords =
|
||||
industry['geo']['coordinates'] as List<dynamic>;
|
||||
final Map<String, dynamic> industryMap =
|
||||
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(
|
||||
(coords[1] as num).toDouble(), (coords[0] as num).toDouble());
|
||||
markers.add(FireMarker(loc, FireMarkType.industry, () {
|
||||
markers.add(fireMarker(loc, FireMarkType.industry, () {
|
||||
_showIndustryDialog(loc);
|
||||
}));
|
||||
// if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel));
|
||||
// if (calibrate) markers.add(fireMarker(loc, FireMarkType.pixel));
|
||||
} catch (e, stackTrace) {
|
||||
reportError(e, stackTrace);
|
||||
}
|
||||
}
|
||||
for (final dynamic fire in fires) {
|
||||
try {
|
||||
final LatLng loc = LatLng(
|
||||
(fire['lat'] as num).toDouble(), (fire['lon'] as num).toDouble());
|
||||
markers.add(FireMarker(loc, FireMarkType.fire, () {
|
||||
onFirePressed(loc, DateTime.parse(fire['when'].toString()),
|
||||
fire['type'] as String);
|
||||
final Map<String, dynamic> fireMap = fire as Map<String, dynamic>;
|
||||
final dynamic lat = fireMap['lat'];
|
||||
final dynamic lon = fireMap['lon'];
|
||||
final dynamic when = fireMap['when'];
|
||||
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) {
|
||||
reportError(e, stackTrace);
|
||||
}
|
||||
}
|
||||
markers.add(
|
||||
FireMarker(pos, isNotif ? FireMarkType.fire : FireMarkType.position));
|
||||
// if (calibrate) markers.add(FireMarker(pos, FireMarkType.pixel));
|
||||
fireMarker(pos, isNotif ? FireMarkType.fire : FireMarkType.position));
|
||||
// if (calibrate) markers.add(fireMarker(pos, FireMarkType.pixel));
|
||||
return markers;
|
||||
}
|
||||
|
||||
void _showFireDialog(LatLng pos, DateTime date, String type) {
|
||||
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)
|
||||
.then((String reverseLoc) {
|
||||
final String by = type == 'vecinal'
|
||||
? S.of(context).byOurUsers
|
||||
: S.of(context).byNASAsatellites;
|
||||
final String fireDesc =
|
||||
S.of(context).additionalInfoAboutFire(reverseLoc, when, by);
|
||||
strings.additionalInfoAboutFire(reverseLoc, when, by);
|
||||
showDialog<bool>(
|
||||
context: _scaffoldKey.currentContext!,
|
||||
builder: (_) => AlertDialog(
|
||||
content: Text(fireDesc),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: Text(S.of(context).CLOSE),
|
||||
child: Text(strings.CLOSE),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(_scaffoldKey.currentContext!);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
|
@ -477,21 +483,22 @@ class GenericMapState extends State<GenericMap> {
|
|||
}
|
||||
|
||||
void _showIndustryDialog(LatLng pos) {
|
||||
final S strings = S.of(context);
|
||||
getReverseLocation(lat: pos.latitude, lon: pos.longitude)
|
||||
.then((String reverseLoc) {
|
||||
final String industryDesc = '${S.of(context).itSeemsAIndustry}\n\n'
|
||||
final String industryDesc = '${strings.itSeemsAIndustry}\n\n'
|
||||
'Type: Industry\n'
|
||||
'Location: $reverseLoc';
|
||||
showDialog<bool>(
|
||||
context: _scaffoldKey.currentContext!,
|
||||
builder: (_) => AlertDialog(
|
||||
title: Text(S.of(context).notAWildfire),
|
||||
title: Text(strings.notAWildfire),
|
||||
content: Text(industryDesc),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: Text(S.of(context).CLOSE),
|
||||
child: Text(strings.CLOSE),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(_scaffoldKey.currentContext!);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
|
@ -500,21 +507,22 @@ class GenericMapState extends State<GenericMap> {
|
|||
}
|
||||
|
||||
void _showFalsePositiveDialog(LatLng pos) {
|
||||
final S strings = S.of(context);
|
||||
getReverseLocation(lat: pos.latitude, lon: pos.longitude)
|
||||
.then((String reverseLoc) {
|
||||
final String falseDesc = '${S.of(context).itSeemsNotAtForesFire}\n\n'
|
||||
final String falseDesc = '${strings.itSeemsNotAtForesFire}\n\n'
|
||||
'Type: False Positive\n'
|
||||
'Location: $reverseLoc';
|
||||
showDialog<bool>(
|
||||
context: _scaffoldKey.currentContext!,
|
||||
builder: (_) => AlertDialog(
|
||||
title: Text(S.of(context).notAWildfire),
|
||||
title: Text(strings.notAWildfire),
|
||||
content: Text(falseDesc),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: Text(S.of(context).CLOSE),
|
||||
child: Text(strings.CLOSE),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(_scaffoldKey.currentContext!);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -112,17 +112,20 @@ class GenericMapBottom extends StatelessWidget {
|
|||
return DropdownMenuItem<FalsePositiveType>(
|
||||
value: value, child: Text(menuText));
|
||||
}).toList(),
|
||||
onChanged: (FalsePositiveType? value) async {
|
||||
onChanged: (FalsePositiveType? value) {
|
||||
final S strings = S.of(context);
|
||||
final ScaffoldMessengerState messenger =
|
||||
ScaffoldMessenger.of(context);
|
||||
if (value != null) {
|
||||
onFalsePositive(notif, value);
|
||||
}
|
||||
await Future<void>.delayed(
|
||||
const Duration(milliseconds: 500));
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(
|
||||
content:
|
||||
Text(S.of(context).thanksForParticipating),
|
||||
Future<void>.delayed(
|
||||
const Duration(milliseconds: 500))
|
||||
.then((_) {
|
||||
messenger.showSnackBar(SnackBar(
|
||||
content: Text(strings.thanksForParticipating),
|
||||
));
|
||||
});
|
||||
}),
|
||||
] as List<Widget>)))));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,13 +30,18 @@ class _GlobalFiresBottomStatsState extends State<GlobalFiresBottomStats> {
|
|||
.then((String result) {
|
||||
try {
|
||||
final Moment now = Moment.now();
|
||||
final DateTime last =
|
||||
DateTime.parse(json.decode(result)['value'] as String);
|
||||
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 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(() {
|
||||
lastCheck = now.from(context, last);
|
||||
activeFires = count;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class LayerSelectorMapPluginWidget extends StatelessWidget {
|
|||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
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 =
|
||||
GlobalKey<PopupMenuButtonState<FireMapLayer>>();
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class FireNotification {
|
|||
factory FireNotification.fromJson(Map<String, dynamic> json) =>
|
||||
_$FireNotificationFromJson(json);
|
||||
@JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson)
|
||||
ObjectId id;
|
||||
final ObjectId id;
|
||||
final double lat;
|
||||
final double lon;
|
||||
final String description;
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ const String fireNotificationKey = 'fireNotifications';
|
|||
|
||||
Future<List<FireNotification>> loadFireNotifications() async {
|
||||
return globals.prefs.then((SharedPreferences prefs) {
|
||||
final List<String>? FireNotifications =
|
||||
final List<String>? fireNotifications =
|
||||
prefs.getStringList(fireNotificationKey);
|
||||
final List<FireNotification> persistedList = <FireNotification>[];
|
||||
for (final String notificationString in (FireNotifications ?? <String>[])) {
|
||||
for (final String notificationString in (fireNotifications ?? <String>[])) {
|
||||
final Map<String, dynamic> notificationMap =
|
||||
json.decode(notificationString) as Map<String, dynamic>;
|
||||
persistedList.add(FireNotification.fromJson(notificationMap));
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ class FiresApi {
|
|||
final String url =
|
||||
'${state.firesApiUrl}fires-in-full/${state.firesApiKey}/$lat/$lon/$distance';
|
||||
if (globals.isDevelopment) {
|
||||
print(url);
|
||||
debugPrint(url);
|
||||
}
|
||||
try {
|
||||
final Response<dynamic> response = await _dio.get(url);
|
||||
|
|
@ -218,7 +218,7 @@ class FiresApi {
|
|||
response.data as Map<String, dynamic>;
|
||||
final Map<String, dynamic> dataData =
|
||||
data['data'] as Map<String, dynamic>;
|
||||
print(dataData['upsert']);
|
||||
debugPrint(dataData['upsert'].toString());
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import '../objectIdUtils.dart';
|
|||
|
||||
part 'yourLocation.g.dart';
|
||||
|
||||
@immutable
|
||||
@JsonSerializable()
|
||||
class YourLocation {
|
||||
YourLocation(
|
||||
|
|
@ -16,20 +15,19 @@ class YourLocation {
|
|||
this.description = '',
|
||||
this.distance = 10,
|
||||
int? currentNumFires,
|
||||
this.subscribed = false}) {
|
||||
this.currentNumFires = currentNumFires ?? 0;
|
||||
}
|
||||
this.subscribed = false})
|
||||
: currentNumFires = currentNumFires ?? 0;
|
||||
|
||||
factory YourLocation.fromJson(Map<String, dynamic> json) =>
|
||||
_$YourLocationFromJson(json);
|
||||
@JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson)
|
||||
ObjectId id;
|
||||
final ObjectId id;
|
||||
final double lat;
|
||||
final double lon;
|
||||
String description;
|
||||
bool subscribed;
|
||||
int distance;
|
||||
late int currentNumFires;
|
||||
int currentNumFires;
|
||||
|
||||
static YourLocation get noLocation {
|
||||
_noLocation ??= YourLocation(id: ObjectId(), lat: 0.0, lon: 0.0);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import 'models/appState.dart';
|
|||
@immutable
|
||||
class _ViewModel {
|
||||
_ViewModel(this.monitoredAreas);
|
||||
List<Polyline> monitoredAreas;
|
||||
final List<Polyline> monitoredAreas;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
|
|
|
|||
|
|
@ -269,10 +269,7 @@ void unsubsViaApi(
|
|||
void subscribeViaApi(Store<AppState> store, YourLocation loc,
|
||||
void Function(YourLocation) onSubs) {
|
||||
api.subscribe(store.state, loc).then((String subsId) {
|
||||
final YourLocation sub = loc;
|
||||
// if (loc.id != subsId) {
|
||||
sub.id = objectIdFromJson(subsId);
|
||||
// }
|
||||
final YourLocation sub = loc.copyWith(id: objectIdFromJson(subsId));
|
||||
onSubs(sub);
|
||||
persistYourLocations(store.state.yourLocations);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue