flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
9.43k stars 360 forks source link

http services have no way to render using webview #3128

Closed hanchenglong001 closed 2 weeks ago

hanchenglong001 commented 2 weeks ago

Description

Packaging HTTP services using IP into Android apps, unable to display using webview

Code example to reproduce the issue:

import time

import flet as ft
import threading
from flask import Flask,send_file

PORT=5448

app = Flask(__name__)
@app.route('/')
def hello_world():
    return send_file("assets/test.html")

def run_flask_in_thread():
    app.run(host='0.0.0.0', port=PORT)

def main(page: ft.Page):
    page.title = "测试工具"
    flask_thread = threading.Thread(target=run_flask_in_thread)
    flask_thread.start()
    page.navigation_bar = ft.NavigationBar(
        destinations=[
            ft.NavigationDestination(icon=ft.icons.EXPLORE, label="首页")
        ]
    )
    wv = ft.WebView(
        url=f"http://127.0.0.1:{PORT}/",
        expand=True,
        on_page_started=lambda _: print("Page start"),
        on_page_ended=lambda _: print("Page ended"),
        on_web_resource_error=lambda e: print("Page error:", e.data),
    )
    page.add(wv)

ft.app(target=main)

images example to reproduce the issue:

image

Describe the results you received: err_cleartext_not_permitted

Describe the results you expected: Can access the service normally. And render the HTML page。

Operating system: Windows python3.9 Android12

requirements.txt

flet==0.22.*
requests==2.31.0
flask==3.0.3