From add46379bd3c641b3fe716bfa2a352e64f22735b Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Fri, 3 Aug 2018 08:47:37 +0200 Subject: [PATCH] Process yourLocations even without response --- lib/redux/fetchDataMiddleware.dart | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/redux/fetchDataMiddleware.dart b/lib/redux/fetchDataMiddleware.dart index 34bbe25..df88ea0 100644 --- a/lib/redux/fetchDataMiddleware.dart +++ b/lib/redux/fetchDataMiddleware.dart @@ -142,16 +142,19 @@ void fetchDataMiddleware(Store store, action, NextDispatcher next) { // Our reducer will then update the State using these YourLocations. // print('Subscribed to: ${subscribedLocations.length}'); loadYourLocations().then((localLocations) { - // unsubscribe all locally to sync the subs state - localLocations.forEach((location) => location.subscribed = false); - // print('Local persisted: ${localLocations.length}'); - subscribedLocations.forEach((subsLoc) { - localLocations.firstWhere( - (localLocation) => localLocation.id == subsLoc.id, orElse: () { - localLocations.add(subsLoc); - }).subscribed = true; - }); - + if (subscribedLocations is List) { + // unsubscribe all locally to sync the subs state + localLocations.forEach((location) => location.subscribed = false); + // print('Local persisted: ${localLocations.length}'); + subscribedLocations.forEach((subsLoc) { + localLocations + .firstWhere( + (localLocation) => localLocation.id == subsLoc.id, orElse: () { + localLocations.add(subsLoc); + }) + .subscribed = true; + }); + } localLocations.forEach((yl) { api.getYourLocationFireStats(store.state, yl).then((value) { yl.currentNumFires = value.numFires;