flet icon indicating copy to clipboard operation
flet copied to clipboard

WebView do not show local html page

Open MusienkoAnton opened this issue 1 year ago • 1 comments

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:

  1. it was near main.py
  2. change code to use url from assets and copy at assets ticket.html

Screenshots

image

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

MusienkoAnton avatar Jun 13 '24 11:06 MusienkoAnton

Also facing same issue any solution

We added some utility methods in the v0.25.0 for this:

ndonkoHenri avatar Dec 01 '24 15:12 ndonkoHenri

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

liuzhuoling2011 avatar Mar 19 '25 10:03 liuzhuoling2011

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 html attribute to WebView class, just like url

I agree

gopalparashar421 avatar Jun 15 '25 20:06 gopalparashar421