deleteEncryptedPlace static method

Future<bool> deleteEncryptedPlace(
  1. String placeId,
  2. BuildContext context,
  3. Widget child
)

Delete an encrypted place by ID. Ensures security key is available before modifying encrypted data.

Implementation

static Future<bool> deleteEncryptedPlace(
  String placeId,
  BuildContext context,
  Widget child,
) async {
  try {
    // Ensure security key is available before fetching/modifying data.
    if (_cachedEncryptedPlaces == null) {
      if (!await ensureSecurityKey(context, child)) {
        debugPrint(
          'Security key not available, cannot safely delete encrypted place',
        );
        return false;
      }
    }

    final existingPlaces =
        _cachedEncryptedPlaces ?? await fetchEncryptedPlaces();
    final updatedPlaces = existingPlaces
        .where((p) => p.id != placeId)
        .toList();
    return await writeEncryptedPlaces(updatedPlaces, context, child);
  } catch (e) {
    debugPrint('Error deleting encrypted place: $e');
    return false;
  }
}