WebView do not show local html page
Duplicate Check
- [X] I have searched the opened issues and there are no duplicates
Describe the bug
I need to show local page "ticket.html" in WebView at Android app. I right simple code and build apk from Windows:
flet build apk --include-packages flet_webview --build-version "0.1.10" --verbose
APK build OK. I try to run at Android phone and see only grey(screenshot)
Code
import flet as ft
def main(page: ft.Page): wv = ft.WebView( url="ticket.html", expand=True, on_page_started=lambda _: print("Page started"), on_page_ended=lambda _: print("Page ended"), on_web_resource_error=lambda e: ft.Text(e.data), ) page.add(wv)
ft.app(main)
To reproduce
Save code at main.py, put near main.py simple ticket.html (with all tags like:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<HTML>
<BODY>
<STYLE>
Build apk using:
flet build apk --include-packages flet_webview --build-version "0.1.10" --verbose
install and run apk on Android phone
Expected behavior
I try to change dir of ticket.html is:
- it was near main.py
- change code to use url from assets and copy at assets ticket.html
Screenshots
Operating System
Linux
Operating system details
Android 14
Flet version
0.22.1
Regression
I'm not sure / I don't know
Suggestions
No response
Additional details
No response
Also facing same issue any solution
Hi @ndonkoHenri , can you give an elegant example how to use load_html()?
I want to init load the page with given html data, but this code will cause Infinite loop (call load_html), too stupid...
import flet as ft
import flet_webview as fwv
def main(page: ft.Page):
html = f"""
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<div>test flet webview</div>
</body>
</html>
"""
wv = fwv.WebView(
url="",
on_page_started=lambda e: e.control.load_html(html),
expand=True,
)
page.add(wv)
ft.app(main)
my suggestion is add html attribute to WebView class, just like url
Hi @ndonkoHenri , can you give an elegant example how to use load_html()?
I want to init load the page with given html data, but this code will cause Infinite loop (call load_html), too stupid...
import flet as ft import flet_webview as fwv
def main(page: ft.Page): html = f"""
Test test flet webview""" wv = fwv.WebView( url="", on_page_started=lambda e: e.control.load_html(html), expand=True, ) page.add(wv)ft.app(main) my suggestion is add
htmlattribute to WebView class, just likeurl
I agree