fetchPlaces static method
Implementation
static Future<List<Place>> fetchPlaces({
bool forceRefresh = false,
bool includeEncrypted = false,
}) async {
final cm = PlacesCacheManager();
if (!forceRefresh) {
final c = cm.allPlaces;
if (c != null) {
// If cached but need encrypted, check if encrypted is included.
if (includeEncrypted && !c.any((p) => p.isEncrypted)) {
// Need to fetch encrypted separately.
} else {
return c;
}
}
}
// Local places are synchronous (compiled into binary) - get them immediately.
final localPlaces = getLocalPlacesSync();
// Fetch network data in parallel for better performance.
final results = await Future.wait([
fetchPodPlaces(forceRefresh: forceRefresh),
includeEncrypted
? fetchEncryptedPlaces(forceRefresh: forceRefresh)
: Future.value(<Place>[]),
]);
final podPlaces = results[0];
final encryptedPlaces = results[1];
final all = <Place>[...podPlaces, ...encryptedPlaces, ...localPlaces];
cm.cacheAllPlaces(all);
return all;
}