Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

IOS Safari File Picker Fixed#1736

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ishaquehassan wants to merge9 commits intomiguelpruivo:master
base:master
Choose a base branch
Loading
fromishaquehassan:master

Conversation

@ishaquehassan
Copy link

@ishaquehassanishaquehassan commentedMar 19, 2025
edited
Loading

PR: Fix iOS Safari File Picker Issue with a Transparent Overlay

Summary

This PR resolves an iOS Safari limitation where a programmatic click (.click()) on an<input type="file"> is blocked. Instead of relying on a virtual click, this solution uses a custom dialog with a transparent, overlaid<input type="file"> element on the “Allow” button to ensure iOS recognizes it as a genuine user interaction.


Background

  • Problem: On iOS Safari,.click() triggers for file inputs are prevented for security reasons.
  • Impact: Users could not upload files on iOS devices if the file picker was triggered without direct user interaction.

Approach

  1. Custom Dialog: Displays a modal asking the user to "Allow" file selection.
  2. Transparent Overlay: Places an<input type="file"> withopacity: 0 on top of the "Allow" button.
    • When tapped, it counts as a legitimate user action, opening the file picker.

Implementation Details

  • Created a dialog component containing the “Allow” button.
  • Positioned a hidden file input over the button with CSS (position: absolute; opacity: 0;).
  • On tap/click, the file picker opens because the user is directly interacting with the file input.

Testing

  • iOS Safari: Confirmed that tapping the “Allow” button now successfully opens the file picker.
  • Cross-Browser: Verified that other browsers still open the file picker correctly.
  • Edge Cases: Tested multiple taps, cancellations, and reopens to ensure stability.

Screenshot

See the attached screenshot showing the dialog with the “Allow” button and the transparent file input overlay.
simulator_screenshot_34C6F370-B68C-4D79-98F6-FD6F6D9C3DA2


By merging this PR, we ensure a consistent, user-friendly file upload experience on iOS Safari, aligning with the direct interaction requirement.

@ishaquehassanishaquehassan changed the title11IOS File Picker FixedMar 19, 2025
@ishaquehassanishaquehassan changed the titleIOS File Picker FixedIOS Safari File Picker FixedMar 19, 2025
- Removed unnecessary import of `html/parser.dart`.- Removed the `_ensureInitialized` function and the related `_kFilePickerInputsDomId`.- Removed the private variable `_target`.- Refactored code to remove parsing of HTML string into document object.- Added a check for null in `_addFileToResult`- added a null check if the file attribute is not null.- Added a null check for the files attribute in the `pickFiles` function.- improved conditional statement for checking isSafariIos
The confirmation modal's styles have been updated to more closely match the style of iOS dialogs. This includes changes to the modal's positioning, background color, borders, shadows, and overall width. The content container, title, detail text, and button container have all been adjusted to improve visual consistency and alignment. Button styles for the "Cancel" and "Allow" actions have also been refined. Added "Don't Allow" and "Allow" text to the buttons.
@navaronbracke
Copy link
Collaborator

This feels more like a workaround, rather than an actual fix? Instead of using a fake dialog, I would look into using a more long term solution.

@navaronbracke
Copy link
Collaborator

navaronbracke commentedMar 19, 2025
edited
Loading

Maybe a long term solution is just to have the input element invisible? (instead ofdisplay="none")
That can be a fix in a few lines, instead of doing all these changes.

The input element is doing that here:https://github.com/miguelpruivo/flutter_file_picker/blob/master/lib/_internal/file_picker_web.dart#L67

Seehttps://stackoverflow.com/questions/26501221/calling-click-event-of-input-doesnt-work-in-safari

@ishaquehassan
Copy link
Author

ishaquehassan commentedMar 19, 2025
edited
Loading

I think we can calculate the element position where file picker is placed and then overlay the input element there.
The reason i did not call it a good solution is that we have to register scroll or drag events too for it. So faking the dialog is the only stable solution with minimum efforts@navaronbracke

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@ishaquehassan@navaronbracke

[8]ページ先頭

©2009-2025 Movatter.jp