Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter] Add file upload on Android #5172

Closed

Conversation

dupuchba
Copy link

@dupuchba dupuchba commented Apr 5, 2022

Currently on Android nothing happens for <input type="file">
This PR solves that by registering the callback onShowFileChooser on the WebView that must returns a Future<List<String>> (list of file path).
It lets you use which-ever file-provider plugin you want to use as recommended by @stuartmorgan here.

Status:

  • Tried it with [image_provider] and it's working
  • Before diving into tests, I hope to have feedbacks on the implementation.
  • Need to read all Contributor guides

Thanks all

Related issues

#3225
flutter/flutter#27924

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@google-cla
Copy link

google-cla bot commented Apr 5, 2022

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).

For more information, open the CLA check for this pull request.

@github-actions github-actions bot added p: webview_flutter Edits files for a webview_flutter plugin platform-android platform-ios labels Apr 5, 2022
Line was not supposed to be committed
@dupuchba dupuchba changed the title [webview_flutter] Add file chooser on Android [webview_flutter] Add file upload on Android Apr 5, 2022
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the submission! At a high level this looks like what was discussed in the previous PR. @bparrishMines should take a high-level look as well.

There is an issue currently blocking moving forward with this though, as noted below (unless we added a different, separate handler object, but that would be ugly).

@@ -27,6 +27,8 @@ abstract class WebViewPlatformCallbacksHandler {
/// /// Only works when [WebSettings.hasProgressTracking] is set to `true`.
void onProgress(int progress);

Future<List<String>> onShowFileChooser();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change as things are currently structured, so adding this will need to wait for the platform interface API update.

@mvanbeusekom @bparrishMines Can we verify that this kind of change will indeed by safe in the updated version?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I don't see any reason this won't be possible with the new interface. The only difference is that we may make this unique to AndroidWebViewControllerDelegate. Which would only slightly change how it is used in this PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bparrishMines what's the branch of the "new interface" ?
I understand that you are refactoring webview_flutter and you want to be sure that this PR will fit the new design.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The work on the new interface can be tracked at: flutter/flutter#94051.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, in the meantime, this PR is stale right ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all of it. The part that adds it to the native api WebChromeClient wrapper should remain valid. Reducing the PR to this will make it easier to add it to the new interface at a later point.

@Hixie
Copy link
Contributor

Hixie commented Jun 7, 2022

@dupuchba Are you interested in following-up with the narrower scope @bparrishMines suggested above?

@dupuchba
Copy link
Author

dupuchba commented Jun 8, 2022

@dupuchba Are you interested in following-up with the narrower scope @bparrishMines suggested above?

Yes I am, I was thinking at adding this when @bparrishMines work would be ready :-) !

@Shubhankt1
Copy link

Shubhankt1 commented Jul 27, 2022

Hi @dupuchba
I had a good working WebView (webview_flutter: ^2.0.4) and I had implemented file upload as well (based on #3225), but after I updated to API version 31, I got the whole new architecture and the whole file upload issue is broken and without knowing that this happened I have released the new app version to public.

I need a way out ASAP. Could you guide me where do I make the change? I am all confused looking at the new arch.

[UPDATE]: I made the changes to the package based on your changes and still it doesn't work.

@dupuchba
Copy link
Author

hey @Shubhankt1 I am going on holidays and I don't have the time to get back at this issue. Last April I said I would make a PR with the new plugin architecture for flutter_webview, once it's done.
If you want to make it work it's pretty straightforward, plus you have my PR as an example. Basically I just wrote some platform code for this method https://developer.android.com/reference/android/webkit/WebChromeClient.html#onShowFileChooser(android.webkit.WebView,%20android.webkit.ValueCallback%3Candroid.net.Uri[]%3E,%20android.webkit.WebChromeClient.FileChooserParams)

@stuartmorgan
Copy link
Contributor

Status update from triage: Still blocked on flutter/flutter#94051, but we hope to have that resolved soon.

@godilite
Copy link

Isn't it frustrating that if this a solution, it cannot be merged for everyone to use?

@dupuchba
Copy link
Author

@godilite to be faire I've not updated my commit to the new platform infrastructure.
And I personally don't think it's frustrating, you can still contribute and make it a reality !

@rashidotm
Copy link

rashidotm commented Dec 18, 2022

Hi.

I am happy to see flutter/flutter#94051 merged which was blocking this.

Now, is there a timeframe for when this will be closed? I am holding an update to my app based on your comments.

thanks and best.

@dupuchba
Copy link
Author

@rashidotm excellent news ! I am probably going to address this in January 23

@bparrishMines
Copy link
Contributor

@dupuchba Thanks for your contribution and patience! I had time to work on this, so I went ahead and created #6881, that uses the new infrastructure of the plugin. I'm going to go ahead and close this one in favor of the other.

@dupuchba
Copy link
Author

@bparrishMines thanks a lot for your time and work.
For what it's worth, it was still on my daily reminder (but I kept pushing it) ^^
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs tests p: webview_flutter Edits files for a webview_flutter plugin platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants