-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[file_selector_web] Listens to file input cancel event. #3683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[file_selector_web] Listens to file input cancel event. #3683
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @raju8000!
Thanks for this fix, however, there's now a cancel
event that AFAIK is supported by almost all browsers (I just verified the event exists in Chrome Canary). See this comment.
Do you mind using that instead of the focus event trick?
I wrote a very small cancel/change event tester app here, because browsers do slightly different things when clicking ok/cancel and selecting the same file or a different one, so some logic will have to be added to figure out if the user was actually canceling the selection:
I think that this now can be solved with a combination of the change
/cancel
without needing to rely on the window focus.
Also, about the tests, please remove the tests that are not really testing the method that you're adding :)
@@ -144,6 +144,65 @@ void main() { | |||
}); | |||
}); | |||
|
|||
group('cancelOpenFiles', () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are not testing anything that this change does :)
@ditman , *https://jsfiddle.net/ditman/avdpr9Lu I have tried above given test app on latest versions of Safari, Chrome & FIrefox, eventually the how could this issue be tackled? |
@raju8000 I can see the "cancel" event in Chrome Beta (v113+) and Safari 16.4, but each browser triggers it differently (that's why "change" and looking at "files" is also needed)
I think the above covers all the possible use cases, but I'm not 100% sure. The idea is that we need to look at both the "change" and "cancel" events, and the "files" of the input to know if the user canceled or not. |
@raju8000 use Google Chrome Canary and Safari Technology Preview, and you will see the cancel event. I noticed it behaves different depending on the browser, just like @ditman said. Here are some examples (for each example, the first action is at the bottom and the the most recent at the top): Chrome Canary: Safari Technology Preview: Firefox(stable not the Nightly version): |
@raju8000 Are you still planning on updating this PR based on the discussion above? |
Thanks @raju8000! I'll review this ASAP! In the meantime, please check the "repo_checks" failure, and try to fix whatever errors it's pointing out. They're usually easy to fix! |
|
I'll try to get this fixed and landed tomorrow, and have a similar fix applied to |
c0b5ec1
to
bbf0c9e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ready to go! (PTAL @stuartmorgan)
e00b088
to
fde3f95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
flutter/packages@2508714...aa1eace 2023-07-13 ian@hixie.ch [rfw] Restore RFW to 100% coverage (flutter/packages#4355) 2023-07-12 65381000+raju8000@users.noreply.github.com [file_selector_web] Listens to file input cancel event. (flutter/packages#3683) 2023-07-12 sam.rawlins@gmail.com [cross_file] Correct sorting of import starting with dot-slash (flutter/packages#4449) 2023-07-12 ian@hixie.ch [metrics_center] Remove Equatable dependency (flutter/packages#4444) 2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter from 3ec96a8 to 544d30d (66 revisions) (flutter/packages#4448) 2023-07-12 stuartmorgan@google.com [ci] Move snippet checks to LUCI (flutter/packages#4446) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@2508714...aa1eace 2023-07-13 ian@hixie.ch [rfw] Restore RFW to 100% coverage (flutter/packages#4355) 2023-07-12 65381000+raju8000@users.noreply.github.com [file_selector_web] Listens to file input cancel event. (flutter/packages#3683) 2023-07-12 sam.rawlins@gmail.com [cross_file] Correct sorting of import starting with dot-slash (flutter/packages#4449) 2023-07-12 ian@hixie.ch [metrics_center] Remove Equatable dependency (flutter/packages#4444) 2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter from 3ec96a8 to 544d30d (66 revisions) (flutter/packages#4448) 2023-07-12 stuartmorgan@google.com [ci] Move snippet checks to LUCI (flutter/packages#4446) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
## Changes This PR listens to the `cancel` event from the `input type=file` used by the web implementation of the image_picker plugin, so apps don't end up endlessly awaiting for a file that will never come **in modern browsers** (Chrome 113, Safari 16.4, or newer). _Same API as #3683 Additionally, this PR: * Removes all code and tests mentioning `PickedFile`. (Deprecated years ago, and unused since #4285) **(Breaking change)** * Updates README to mention `XFile` which is the current return type of the package. * Updates the dependency on `image_picker_platform_interface` to `^2.9.0`. * Implements all non-deprecated methods from the interface, and makes deprecated methods use the fresh ones. * Updates tests. ### Issues * Fixes flutter/flutter#92176 ### Testing * Added integration testing coverage for the 'cancel' event. * Tested manually in Chrome with the example app running on web.
While using package
file_selector
making for multiple file request in web platform we are not able to get any data if user clicks cancel button on file selection window. This PR fixes it by watching thefocus event
and ifonChange
is not fired then return empty array, Empty array will only return if multiple selection is enabled withopenFiles()
.List which issues are fixed by this PR. You must list at least one issue.
Issue #121328
Pre-launch Checklist
dart format
.)[shared_preferences]
///
).