This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[webview_flutter] Add interface methods to load local files and HTML strings. #4446
Merged
mvanbeusekom
merged 8 commits into
flutter:master
from
Baseflow:feature/webview_load_asset
Nov 4, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4b7a63f
Add methods to load HTML and Flutter assets.
mvanbeusekom 3151008
Renamed loadHtml to loadHtmlString
mvanbeusekom 0f28905
Support loading arbitrary files instead of only Flutter assets
mvanbeusekom 7a0c69a
Update changelog description
mvanbeusekom c126eb6
Merge branch 'master' into feature/webview_load_asset
mvanbeusekom 7a59328
Rebase with master
mvanbeusekom b2efaa8
Fix formatting
mvanbeusekom 0f70b11
Fix formatting
mvanbeusekom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.