- introPage.dart: Convert fireItems to proper static function closure - mainDrawer.dart: Convert unreadCount int to String for Text widget
34 lines
1.3 KiB
Dart
34 lines
1.3 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
import 'package:comunes_flutter/comunes_flutter.dart';
|
|
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.where(notNull).toList().forEach((FireNotification notification) {
|
|
notifAsString.add(json.encode(notification.toJson()));
|
|
});
|
|
prefs.setStringList(fireNotificationKey, notifAsString);
|
|
});
|
|
}
|