loadEncryptedPlacesData function

Future<LoadEncryptedPlacesResult> loadEncryptedPlacesData({
  1. required BuildContext context,
  2. required Widget widget,
  3. required bool isLoggedIn,
  4. required bool skipKeyVerification,
})

Load encrypted places on demand when user enables the setting. If skipKeyVerification is true, assumes security key is already verified.

Implementation

Future<LoadEncryptedPlacesResult> loadEncryptedPlacesData({
  required BuildContext context,
  required Widget widget,
  required bool isLoggedIn,
  required bool skipKeyVerification,
}) async {
  if (!isLoggedIn) {
    return LoadEncryptedPlacesResult(encryptedPlaces: [], cancelled: true);
  }

  if (!skipKeyVerification) {
    // Ensure security key is available (will prompt user if needed)
    final hasKey = await EncryptedPlacesService.ensureSecurityKey(
      context,
      widget,
    );
    if (!hasKey) {
      // User cancelled or key not available.
      return LoadEncryptedPlacesResult(encryptedPlaces: [], cancelled: true);
    }
  }

  try {
    final encryptedPlaces = await PlacesService.fetchEncryptedPlaces(
      forceRefresh: true,
    );
    return LoadEncryptedPlacesResult(encryptedPlaces: encryptedPlaces);
  } catch (e) {
    debugPrint('Error loading encrypted places: $e');
    return LoadEncryptedPlacesResult(encryptedPlaces: [], error: e.toString());
  }
}