Comments (13)
On Windows, you could use something like
import 'dart:io';
import 'package:path/path.dart' as p;
String getAssetFileUrl(String asset) {
final assetsDirectory = p.join(
p.dirname(Platform.resolvedExecutable), 'data', 'flutter_assets', asset);
return Uri.file(assetsDirectory).toString();
}
from flutter-webview-windows.
String getAssetFileUrl(String asset) {What would be the value of string asset in parameter,
controller.loadUrl(getAssetFileUrl('assets/test.html'));
from flutter-webview-windows.
@yisar I don't think there is eample project on this, let me know if you need. I will post example to this
Updated: Here is the medium link
from flutter-webview-windows.
- though I am able to load html content, Js file is't working using (loadStringContent function),
Do you mean scripts that are loaded from the HTML (string) document or a directly run script using executeScript
?
It might be an issue with the URLs of the resources you want to load. You’re using relative URLs, right?
I don’t know what they’re relative to. Might be the current working directory.
If the document is placed in a file anyway, why don’t you just load it via loadUrl('file://...')
?
- Also communication between dart and html js is't working and vice versa.
If the feature is implemented please provide example for each cases, if not I hope this feature will come soon
On the dart side, messages can be posted to the webview with postWebMessage
and received by listening to the webMessage
stream.
On the web side, you need to use window.chrome.webview.addEventListener('message', handler);
(see https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2?view=webview2-1.0.864.35#postwebmessageasjson and https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2?view=webview2-1.0.864.35#add_webmessagereceived)
from flutter-webview-windows.
Thank you @jnschulze for the respond, let me elaborate my approach:
-
I have test.html which has few html content and link to js and css, eg <script src="test.js"></script>, though I am able to load the html I am not able to trigger .js function.
So I meant script from html, not executeScript and all document are placed inside app assets folder. -
For communication,
a. Say I have button in flutter app bar when I click on app bar button it should call function defined in js file and display alert as such
b. When I click html button in webview, it should able to call dart function and display toast or snackbar or something
PS. I was able to do in webview for mobile and web and now trying on window desktop
from flutter-webview-windows.
- I have test.html which has few html content and link to js and css, eg <script src="test.js"></script>, though I am able to load the html I am not able to trigger .js function.
So I meant script from html, not executeScript and all document are placed inside app assets folder.
Okay, I’d just use loadUrl as opposed to loadStringContent then.
from flutter-webview-windows.
Okay, I’d just use loadUrl as opposed to loadStringContent then.
what would be the url then I tried "file://assets/test.html" and didt work
from flutter-webview-windows.
String getAssetFileUrl(String asset) {
What would be the value of string asset in parameter,
I think it would be nice if you include this in example project in your repo too for loading html content in webview, for now I can see only url in your code.
from flutter-webview-windows.
@jnschulze thanks, it worked. Loading html,js content from assets.You can close this issue, But I was still wondering, How can we communicate between webview to dart and vice versa as mentioned above. Is it possible with current version or can you do that in future.
from flutter-webview-windows.
It's possible by posting a message to the current document as described above.
from flutter-webview-windows.
On the dart side, messages can be posted to the webview with postWebMessage and received by listening to the webMessage stream.
Is there a complete demo here?
from flutter-webview-windows.
On the dart side, messages can be posted to the webview with postWebMessage and received by listening to the webMessage stream.
Is there a complete demo here?
Unfortunately not, but using it should be straightforward and won’t take more than five minutes to wire up.
from flutter-webview-windows.
I use loadUrl(getAssetFileUrl('assets/test.html')) it work the image show
but when use loadStringContent(html) the image doesn,t show
I want to use loadStringContent how to fix this problem
from flutter-webview-windows.
Related Issues (20)
- Ignore SSL error
- Can i read resources from local cache data?
- [crash] I encountered the following crash, is there any way to solve it?
- How to prevent right click ? HOT 4
- Building Error
- onUrlChanged
- Dropdown Not Working in windows Webview HOT 3
- Need suggestion to Hide Scrollbar on Webview HOT 2
- Creating the webview failed: CreateCoreWebView2CompositionController copletion handler failed. (HRESULT: -0x7ff8ec61) HOT 2
- Error running the project in the child window created using plugin desktop_multi_window
- Error running the project in the child window
- usermedia.edgeGrantPermission Error HOT 4
- postWebMessage failed HOT 2
- JavaScript
- css, javascript and images load from document directory
- Error building flutter windows build
- 2
- how to add addJavaScriptChannel? HOT 1
- HTML has its own defined scrollbar, and the mouse wheel cannot scroll HOT 5
- Webview not accessible
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter-webview-windows.