clearAllPlaces static method

Future<bool> clearAllPlaces(
  1. BuildContext context,
  2. Widget returnWidget
)

Implementation

static Future<bool> clearAllPlaces(
  BuildContext context,
  Widget returnWidget,
) async {
  try {
    if (!authStateNotifier.value) return false;

    // Get all existing place IDs before clearing.
    final existing = await fetchPodPlaces();
    final placeIds = existing.map((p) => p.id).toList();

    final success = await writePlacesJsonFile('[]');
    if (success) {
      // Delete all individual place files.
      await deleteAllIndividualPlaceFiles(placeIds);
      await clearCache();
      placesChangeNotifier.value++;

      // Invalidate directory cache and notify file browser.

      PodDirectoryService.invalidateCache('data/places');
      PodDirectoryService.notifyChange();
    }
    return success;
  } catch (_) {
    return false;
  }
}