performBackgroundSave function
- Place originalPlace,
- BuildContext context, {
- bool encrypted = false,
Performs background save of a place with address lookup.
Note: Context is passed through to PlacesService which handles mounted checks internally.
If encrypted is true, saves to encrypted storage.
Implementation
Future<Place?> performBackgroundSave(
Place originalPlace,
BuildContext context, {
bool encrypted = false,
}) async {
final address = await GeocodingService.getAddress(
originalPlace.lat,
originalPlace.lng,
);
final updatedPlace = Place(
id: originalPlace.id,
lat: originalPlace.lat,
lng: originalPlace.lng,
note: originalPlace.note,
timestamp: originalPlace.timestamp,
address: address,
isEncrypted: encrypted,
);
if (!context.mounted) return null;
bool success;
if (encrypted) {
// Save to encrypted storage.
success = await EncryptedPlacesService.addEncryptedPlace(
updatedPlace,
context,
const GeoMapWidget(),
);
} else {
// Save to regular storage.
success = await PlacesService.addPlace(
updatedPlace,
context,
const GeoMapWidget(),
);
}
if (success) {
return updatedPlace;
} else {
throw Exception(encrypted ? 'Encrypted save failed' : 'WritePod failed');
}
}