[image_picker] Handle limit: 1 in pickMultiImage and pickMultipleMedia gracefully#11825
Open
yashas-hm wants to merge 7 commits into
Open
[image_picker] Handle limit: 1 in pickMultiImage and pickMultipleMedia gracefully#11825yashas-hm wants to merge 7 commits into
yashas-hm wants to merge 7 commits into
Conversation
…into fix/issue-187347-limit-1-error
There was a problem hiding this comment.
Code Review
This pull request updates ImagePicker to delegate to single-item pickers (pickImage and pickMedia) when pickMultiImage or pickMultipleMedia is called with a limit of 1, preventing an ArgumentError since multi-image selection requires a limit of at least 2. The changes include corresponding unit tests and a CHANGELOG update. The reviewer recommends updating the CHANGELOG entry to explicitly mention the fix for pickMultipleMedia alongside pickMultiImage.
Comment on lines
+3
to
+5
| * Fixes `pickMultiImage(limit: 1)` throwing an `ArgumentError` by delegating | ||
| to `pickImage` when `limit` is exactly 1, since the platform interface | ||
| requires `limit >= 2` for multi-image selection. |
There was a problem hiding this comment.
The CHANGELOG entry only mentions pickMultiImage(limit: 1), but the PR also fixes pickMultipleMedia(limit: 1). Please update the CHANGELOG to reflect both fixes.
For example:
* Fixes `pickMultiImage(limit: 1)` and `pickMultipleMedia(limit: 1)` throwing an `ArgumentError` by delegating to single-item pickers when `limit` is exactly 1, since the platform interface requires `limit >= 2` for multi-selection.
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.
Summary
Fixes flutter/flutter#187347
pickMultiImage(limit: 1)andpickMultipleMedia(limit: 1)previouslythrew:
because
MultiImagePickerOptionsandMediaOptionsin the platforminterface both reject
limit < 2.Fix
When
limit == 1, the facade now delegates to the equivalentsingle-item picker instead of forwarding to the platform:
pickMultiImage(limit: 1)→ delegates topickImage(source: ImageSource.gallery, ...)pickMultipleMedia(limit: 1)→ delegates topickMedia(...)The result is wrapped in a single-element list, or an empty list if the
user cancelled.
limit <= 0still throws as before.Why the facade, not the platform interface
The
limit < 2guard inMultiImagePickerOptionsandMediaOptionsexists because the underlying platform multi-picker APIs genuinely do not
support selecting exactly one item, they require at least two. Relaxing
the validation in the platform interface would push the burden onto every
platform implementation to handle a case their native API may not
support, risking silent misbehaviour on some platforms.
The facade (
image_picker) is the right place for this: it already ownsthe user-facing API contract and can transparently route
limit: 1tothe well-tested single-item pickers without touching any platform code.
Tests
limit: 1delegates togetImageFromSourcewithImageSource.gallery(pickMultiImage)limit: 1delegates togetMediawithallowMultiple: false(pickMultipleMedia)limit: 0andlimit: -1still throwArgumentErrorPre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Closes flutter/flutter#187347
Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2