packages icon indicating copy to clipboard operation
packages copied to clipboard

[image_picker_ios] infinite await in picking methods when native picker is closed quickly

Open raju-muliyashiya opened this issue 1 month ago • 1 comments

fixes Issue #134715

Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.

List which issues are fixed by this PR. You must list at least one issue.

Pre-Review Checklist

  • [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • [x] I read the [Tree Hygiene] page, which explains my responsibilities.
  • [x] I read and followed the [relevant style guides] and ran [the auto-formatter].
  • [x] I signed the [CLA].
  • [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • [x] I [linked to at least one issue that this PR fixes] in the description above.
  • [x] I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or I have commented below to indicate which [version change exemption] this PR falls under[^1].
  • [x] I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style], or I have commented below to indicate which [CHANGELOG exemption] this PR falls under[^1].
  • [x] I updated/added any relevant documentation (doc comments with ///).
  • [x] I added updated tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
  • [x] All existing and new tests are passing.

This PR implements a robust observer mechanism to detect when the picker view controller is removed from the window hierarchy, ensuring the Flutter Future always completes—even during immediate dismiss.

Key Changes Made

➤ Added FLTImagePickerRemoveCallback

A callback function responsible for cleanup when the picker is dismissed.

➤ Implemented FLTImagePickerRemoveObserverView

A UIView subclass that monitors picker dismissal by:

  • Observing changes to the window property via didMoveToWindow
  • Detecting when the picker is removed from the screen
  • Triggering the callback to complete the Flutter Future with nil (indicating cancellation)

➤ Integrated Observer in bindRemoveObserver

Automatically attaches the observer to picker controllers to handle:

  • Interactive dismissal gestures
  • Programmatic dismissals
  • Quick dismissals before full presentation

raju-muliyashiya avatar Nov 18 '25 07:11 raju-muliyashiya

@raju-muliyashiya can you add a description to your pr and address the gemini comments ?

okorohelijah avatar Nov 25 '25 22:11 okorohelijah