diff --git a/lib/models/fireNotificationsPersist.dart b/lib/models/fireNotificationsPersist.dart index a68ffbe..f0d9aa3 100644 --- a/lib/models/fireNotificationsPersist.dart +++ b/lib/models/fireNotificationsPersist.dart @@ -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> 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 notif) { print('Persisting $notif'); globals.prefs.then((prefs) { List notifAsString = []; - notif.forEach((notification) { + notif.where(notNull).toList().forEach((notification) { notifAsString.add(json.encode(notification.toJson())); }); prefs.setStringList(fireNotificationKey, notifAsString); diff --git a/lib/models/yourLocationPersist.dart b/lib/models/yourLocationPersist.dart index bce5885..e533d4f 100644 --- a/lib/models/yourLocationPersist.dart +++ b/lib/models/yourLocationPersist.dart @@ -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> 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 yl) { print('Persisting $yl'); globals.prefs.then((prefs) { List ylAsString = []; - yl.forEach((location) { + yl.where(notNull).toList().forEach((location) { ylAsString.add(json.encode(location.toJson())); }); prefs.setStringList(locationKey, ylAsString);