-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[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
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,24 @@ class MethodChannelWebViewPlatform implements WebViewPlatformController { | |
); | ||
} | ||
|
||
@override | ||
Future<void> loadFlutterAsset(String assetName) async { | ||
assert(assetName != null); | ||
return _channel.invokeMethod<void>('loadFlutterAsset', assetName); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 The |
||
|
||
@override | ||
Future<void> loadHtml( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Renamed. |
||
String html, { | ||
String? baseUrl, | ||
}) async { | ||
assert(html != null); | ||
return _channel.invokeMethod<void>('loadHtml', <String, dynamic>{ | ||
'html': html, | ||
'baseUrl': baseUrl, | ||
}); | ||
} | ||
|
||
@override | ||
Future<void> loadUrl( | ||
String url, | ||
|
Uh oh!
There was an error while loading. Please reload this page.