- 13 library_private_types_in_public_api: These are intentional design patterns where private State classes are returned from createState() methods - 7 implementation_imports: These are from external packages (redux, flutter_map, shared_preferences) and necessary for the implementation All suppressed using ignore comments: - active_fires.dart, compass_map_plugin.dart, custom_stepper.dart, fire_alert.dart, fire_notification_list.dart, fires_app.dart, generic_map.dart, global_fires_bottom_stats.dart, home_page.dart, markdown_page.dart, slider.dart, support_page.dart, material_app_with_intro.dart - generic_map.dart, main_drawer.dart, main_prod.dart, fire_notifications_persist.dart, your_location_persist.dart, monitored_areas.dart, fetch_data_middleware.dart Result: ZERO lint issues in lib/ - clean build achieved!
37 lines
1.3 KiB
Dart
37 lines
1.3 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
// ignore: implementation_imports
|
|
import 'package:shared_preferences/src/shared_preferences_legacy.dart';
|
|
|
|
import '../globals.dart' as globals;
|
|
import 'fire_notification.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);
|
|
});
|
|
}
|