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

[webview_flutter_android] Adds support for receiving Java callback WebChromeClient.onShowFileChooser #6881

Merged
merged 36 commits into from
Jan 19, 2023

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Dec 24, 2022

  • Adds WebChromeClient.onShowFileChooser callback method.
  • Adds FileChooserParams class since its passed to onShowFileChooser.
  • Adds AndroidWebViewController.setOnShowFileSelector.
  • Moves WebChromeClient from AndroidNavigationDelegate to AndroidWebViewController since the callback is set by the controller.

Note: This callback is only supported for versions 21+.

Fixes flutter/flutter#27924 and flutter/flutter#97127

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.

@github-actions github-actions bot added p: webview_flutter Edits files for a webview_flutter plugin platform-android labels Dec 24, 2022
@bparrishMines bparrishMines changed the title On show file chooser [webview_flutter_android] Adds support for receiving Java callback WebChromeClient.onShowFileChooser Dec 25, 2022
@stuartmorgan-g
Copy link
Contributor

So, I added a helper method (FileChooserParams.openFilePickerForResult()) that handles starting an Activity and retrieving the result.

I was thinking that openFilePickerForResult could be used as the default functionality for Android. Therefore, a user wouldn't need the file_picker plugin to handle this.

I thought the decision from the previous discussion of option was that we would start with not providing a default, and suggest that people use file_selector as the implementation, so that we didn't have to maintain two copies of essentially the same code that we already have in file_selector (flutter/flutter#27924 (comment)). Why the change in approach? Could we scope this PR down to just providing the callback part without a default implementation or helper, release that, and see if we actually need more that just an example of implementing it with file_selector (or maybe directly with file_selector_android to cut down on overhead to other platforms)?

@stuartmorgan-g
Copy link
Contributor

I assume this PR will obsolete #5172?

@dupuchba
Copy link

Thank you both for your work 🙇

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

A couple of questions, but overall LGTM!

Once file_selector_android lands we should consider updating the example app for this package to show using it to handle this callback.

fileChooserParams,
reply -> {
// The returned list of file paths can only be passed to `filePathCallback` if the
// `onShowFileChooser` method returned true.
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we just not call flutterApi.onShowFileChooser in the first place if this is true? Or is the idea that you could in theory want to know when it's called (on the Dart side) without actually handling it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I assumed there could be a situation where someone could want to know when a user clicks on the <input name="userfile" type="file"> button. I don't think it hurts to keep it this way.

) {
assert(
!value || onShowFileChooser != null,
'Setting this to true requires `onShowFileChooser` to be nonnull.',
Copy link
Contributor

Choose a reason for hiding this comment

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

assert is debug-only; this should probably be a StateError.

@rashidotm
Copy link

Thanks for the effort. I am looking forward to upgrade as soon as it is released. 🔥🔥

Approximately, what is the timeline on it?

@stuartmorgan-g
Copy link
Contributor

As with all PRs, it will land when it's fully reviewed and approved.

@bparrishMines bparrishMines added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 19, 2023
@auto-submit auto-submit bot merged commit 5f44021 into flutter:main Jan 19, 2023
@bparrishMines bparrishMines deleted the onShowFileChooser branch January 20, 2023 04:09
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
…ebChromeClient.onShowFileChooser` (flutter#6881)

* some progress

* more work

* compiling code

* dart side should be correct

* maybe working code

* fix plugin class

* formatting

* some docs and polish

* foramtting tests and docs

* version bump

* doc improvements

* flutterapi create test

* working java test

* unused imports

* formatting and more tests

* formatting and more tests

* formatting

* copy and tests

* add more description to the custom method

* formatting

* change doc wording

* more docs

* null out result early

* remove the open option

* fix spelling

* interface implementation

* version bump

* move webchromeclient to webview controller

* tests

* reference method in changelong

* missing typed data import

* undo changes

* use stateerror instead

* updated lints
@kennetgo
Copy link

kennetgo commented Feb 1, 2023

Can somebody please provide an example code to use setOnShowFileSelector, for an AndroidWebViewController. Thanks

@stuartmorgan-g
Copy link
Contributor

@kennetgo flutter/flutter#118836 is tracking that, as mentioned in the original issue.

@faccioliandrea

This comment was marked as duplicate.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App 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.

[webview_flutter] not working choose file (input type file)
6 participants