validateSavedEncryptedSetting function

Future<bool> validateSavedEncryptedSetting({
  1. required MapSettings mapSettings,
  2. required bool isLoggedIn,
  3. required List<Place> allPlaces,
})

Validates the saved encrypted places setting. Returns true if validation passed and encrypted places should be loaded.

Implementation

Future<bool> validateSavedEncryptedSetting({
  required MapSettings mapSettings,
  required bool isLoggedIn,
  required List<Place> allPlaces,
}) async {
  if (!mapSettings.showEncryptedPlaces) return false;

  if (!isLoggedIn) {
    // Not logged in, setting should be reset.
    return false;
  }

  // Check if encrypted places are already loaded.
  final hasEncryptedPlaces = allPlaces.any((p) => p.isEncrypted);
  if (hasEncryptedPlaces) {
    debugPrint(
      'validateSavedEncryptedSetting: encrypted places already loaded, skipping',
    );
    return false;
  }

  // Check if security key is already available.
  final hasKey = await EncryptedPlacesService.isSecurityKeyAvailable();
  debugPrint(
    'validateSavedEncryptedSetting: hasKey=$hasKey, will load encrypted places',
  );

  // Always return true to trigger loading (will prompt for key if needed)
  return true;
}