loadPlacesWithState function

Future<LoadPlacesResult> loadPlacesWithState({
  1. required List<Place> currentPlaces,
  2. required bool forceRefresh,
  3. required bool includeEncrypted,
})

Loads all places (local and pod) with optional encrypted places.

Implementation

Future<LoadPlacesResult> loadPlacesWithState({
  required List<Place> currentPlaces,
  required bool forceRefresh,
  required bool includeEncrypted,
}) async {
  final cacheManager = PlacesCacheManager();
  final showLoading = cacheManager.allPlaces == null;

  final places = await loadAllPlaces(
    forceRefresh: forceRefresh,
    includeEncrypted: includeEncrypted,
  );

  // Check if data actually changed to avoid unnecessary rebuild.
  final hasChanges =
      currentPlaces.length != places.length ||
      !currentPlaces.every((p) => places.any((np) => np.id == p.id));

  return LoadPlacesResult(
    places: places,
    showLoading: showLoading,
    hasChanges: hasChanges || showLoading,
  );
}