Dismiss the iOS native editor when the contact is deleted from it - #249
Open
liliana-tagonsoft wants to merge 1 commit into
Open
Dismiss the iOS native editor when the contact is deleted from it#249liliana-tagonsoft wants to merge 1 commit into
liliana-tagonsoft wants to merge 1 commit into
Conversation
CNContactViewController's "Delete Contact" row never calls contactViewController(_:didCompleteWith:), so showEditor's sheet stays on screen and its Future never completes. Observe CNContactStoreDidChange while the editor is up and close it once the edited contact is gone.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On iOS,
FlutterContacts.native.showEditor(contactId)presents aCNContactViewControllerwithallowsEditing = true. Tapping the editor's Delete Contact row deletes the contact, but:contactViewController(_:didCompleteWith:)is never called, so the sheet stays on screen with anow-deleted contact still rendered in it;
showEditorFuture doesn't complete until the user closes the sheet by hand — the controlleris presented in editing mode, so it shows its own ✕ / ✓ items rather than the injected Done
button — and it then resolves to
null, indistinguishable from "cancelled", so the app has no wayto know the contact was deleted;
showEditoragain for the same id then throwsPlatformException(flutter_contacts_error, Updated Record Does Not Exist), becausestore.unifiedContact(withIdentifier:)fails on the deleted identifier.Note the Delete Contact row only appears in a third-party
CNContactViewControlleron iOS 26+(it isn't offered on earlier versions), which is probably why this hasn't come up before.
Fix
While the editor is presented, observe
.CNContactStoreDidChange. When a store change arrives andunifiedContact(withIdentifier:)no longer returns the edited contact, dismiss the editor andcomplete the pending result with
nil. The dismissal goes throughnavController.presentingViewControllerso the delete confirmation sheet, if it's still animatingout, goes away with the editor. The observer is removed in
completeWithResult, so it's torn downon every exit path (delegate, close, deletion).
Saves are unaffected: the notification also fires on a normal edit, but the contact still resolves,
so the observer returns early and the existing delegate path handles it.
Testing
Tested in a production app on the iOS 26.3 simulator (iPhone 17 Pro):
showEditorcompleteswith
null.null.Notes
showEditorstill returnsnullfor both "cancelled" and "deleted". Distinguishing them would needan API change (e.g. a sentinel or a richer result), so this PR keeps the signature and just fixes
the stuck sheet — happy to follow up with that if you'd like it.