Better persisting
This commit is contained in:
parent
c39351d0df
commit
04cc6fef83
2 changed files with 16 additions and 12 deletions
|
|
@ -2,7 +2,7 @@ import 'dart:async';
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:fires_flutter/models/fireNotification.dart';
|
||||
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import '../globals.dart' as globals;
|
||||
|
||||
final String fireNotificationKey = 'fireNotifications';
|
||||
|
|
@ -16,10 +16,12 @@ Future<List<FireNotification>> loadFireNotifications() async {
|
|||
// first run, init with empty list
|
||||
persistFireNotifications(persistedList);
|
||||
}
|
||||
FireNotifications.forEach((notificationString) {
|
||||
Map notificationMap = json.decode(notificationString);
|
||||
persistedList.add(FireNotification.fromJson(notificationMap));
|
||||
});
|
||||
if (FireNotifications is List) {
|
||||
FireNotifications.forEach((notificationString) {
|
||||
Map notificationMap = json.decode(notificationString);
|
||||
persistedList.add(FireNotification.fromJson(notificationMap));
|
||||
});
|
||||
}
|
||||
return persistedList;
|
||||
});
|
||||
}
|
||||
|
|
@ -28,7 +30,7 @@ persistFireNotifications(List<FireNotification> notif) {
|
|||
print('Persisting $notif');
|
||||
globals.prefs.then((prefs) {
|
||||
List<String> notifAsString = [];
|
||||
notif.forEach((notification) {
|
||||
notif.where(notNull).toList().forEach((notification) {
|
||||
notifAsString.add(json.encode(notification.toJson()));
|
||||
});
|
||||
prefs.setStringList(fireNotificationKey, notifAsString);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import 'dart:async';
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:fires_flutter/models/yourLocation.dart';
|
||||
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import '../globals.dart' as globals;
|
||||
|
||||
final String locationKey = 'yourlocations';
|
||||
|
|
@ -16,10 +16,12 @@ Future<List<YourLocation>> loadYourLocations() async {
|
|||
// first run, init with empty list
|
||||
persistYourLocations(persistedList);
|
||||
}
|
||||
yourLocations.forEach((locationString) {
|
||||
Map locationMap = json.decode(locationString);
|
||||
persistedList.add(YourLocation.fromJson(locationMap));
|
||||
});
|
||||
if (yourLocations is List) {
|
||||
yourLocations.forEach((locationString) {
|
||||
Map locationMap = json.decode(locationString);
|
||||
persistedList.add(YourLocation.fromJson(locationMap));
|
||||
});
|
||||
}
|
||||
return persistedList;
|
||||
});
|
||||
}
|
||||
|
|
@ -28,7 +30,7 @@ persistYourLocations(List<YourLocation> yl) {
|
|||
print('Persisting $yl');
|
||||
globals.prefs.then((prefs) {
|
||||
List<String> ylAsString = [];
|
||||
yl.forEach((location) {
|
||||
yl.where(notNull).toList().forEach((location) {
|
||||
ylAsString.add(json.encode(location.toJson()));
|
||||
});
|
||||
prefs.setStringList(locationKey, ylAsString);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue