- 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
36 lines
1.2 KiB
Dart
36 lines
1.2 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
import 'package:shared_preferences/src/shared_preferences_legacy.dart';
|
|
|
|
import '../globals.dart' as globals;
|
|
import 'fireNotification.dart';
|
|
|
|
const String fireNotificationKey = 'fireNotifications';
|
|
|
|
Future<List<FireNotification>> loadFireNotifications() async {
|
|
return globals.prefs.then((SharedPreferences prefs) {
|
|
final List<String>? fireNotifications =
|
|
prefs.getStringList(fireNotificationKey);
|
|
final List<FireNotification> persistedList = <FireNotification>[];
|
|
for (final String notificationString in (fireNotifications ?? <String>[])) {
|
|
final Map<String, dynamic> notificationMap =
|
|
json.decode(notificationString) as Map<String, dynamic>;
|
|
persistedList.add(FireNotification.fromJson(notificationMap));
|
|
}
|
|
return persistedList;
|
|
});
|
|
}
|
|
|
|
void persistFireNotifications(List<FireNotification> notif) {
|
|
// print('Persisting $notif');
|
|
globals.prefs.then((SharedPreferences prefs) {
|
|
final List<String> notifAsString = <String>[];
|
|
notif
|
|
.whereType<FireNotification>()
|
|
.forEach((FireNotification notification) {
|
|
notifAsString.add(json.encode(notification.toJson()));
|
|
});
|
|
prefs.setStringList(fireNotificationKey, notifAsString);
|
|
});
|
|
}
|