This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
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.
[webview_flutter] Add interface methods to load local files and HTML strings. #4446
[webview_flutter] Add interface methods to load local files and HTML strings. #4446
Changes from 1 commit
4b7a63f
3151008
0f28905
7a0c69a
c126eb6
7a59328
b2efaa8
0f70b11
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
You've listed issues for both assets and arbitrary local files in the PR description; why are we restricting to assets here?
It's not clear to me that we should actually support assets on a per-plugin basis, in fact, since there are other cases where someone may want asset paths (e.g., FFI). It might make more sense to just support file paths, and then have a dedicated plugin (or maybe a function in
path_provider
) to get asset paths.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.
As far as I know, it is not possible to load files in the WKWebView control that live outside the application bundle (due to security reasons). By only allowing loading of Flutter assets you force developers to add their HTML files as part of the iOS bundle ensuring that the file is always available and can be loaded.
This might be a bit restrictive to other platforms however I think it will cover most use cases where people wish to load local files. At least that was my reasoning.
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.
Do you have a source for that? It's not a documented restriction of the file-loading API.
One of the issues you linked is explicitly about a use case where assets wouldn't work; I don't think we have any data on how common one or the other use case is.
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.
No I don't have any documentation to back that up. And there are indeed samples that allow you to load information from for example the Documents directory. My bad.
I will update the interface to accept an absolute file path instead.
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.
Done. I those to accept only the absolute file path as that seems to be the easiest way to work cross platform.
On Android the
WebView.loadUrl
method requires the path to be prefixed withfile://
(which we can take care of internally).The
[WKWebView loadFileURL:]
only accepts an instance of theNSURL
class which can easily be created from the absolute path using the[NSURL fileURLWithPath:]
method.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.
How about loadHtmlString; we expect all of the mechanism for loading to provide HTML so this seems confusingly vague.
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.
Renamed.