handleOptimisticPlaceSave function
Handles optimistic save of a place.
Updates UI immediately, then performs background save.
If encrypted is true, the place will be marked as encrypted for
immediate purple marker display.
Implementation
void handleOptimisticPlaceSave({
required Place place,
required List<Place> allPlaces,
required Set<String> savingPlaceIds,
required BuildContext context,
required void Function(void Function()) setState,
required Future<void> Function(Place) performBackgroundSave,
bool encrypted = false,
}) {
// Mark place as encrypted if saving to encrypted storage.
final placeToSave = encrypted ? place.copyWith(isEncrypted: true) : place;
// Update state first.
setState(() {
allPlaces.insert(0, placeToSave);
savingPlaceIds.add(placeToSave.id);
});
// Show snackbar after frame to avoid jank.
SchedulerBinding.instance.addPostFrameCallback((_) {
if (context.mounted) {
showSavingSnackbar(context, placeToSave);
}
});
// Start background save.
unawaited(performBackgroundSave(placeToSave));
}