Skip to content

LaunchMode 继承自: Enum

Preferred launch mode for opening a URL.

示例 ​

python
import flet as ft


def main(page: ft.Page):
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
    launcher = ft.UrlLauncher()

    def showcase_card(mode: ft.LaunchMode) -> ft.Container:
        status = ft.Text("Click to check support on this platform.", size=11)

        async def check_support():
            try:
                supported = await launcher.supports_launch_mode(mode)
                closable = await launcher.supports_close_for_launch_mode(mode)
                status.value = (
                    f"supports_launch_mode={supported} / supports_close={closable}"
                )
            except Exception as ex:
                status.value = f"Error: {ex}"
            status.update()

        return ft.Container(
            width=360,
            padding=12,
            border=ft.Border.all(1, ft.Colors.RED),
            border_radius=10,
            bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
            content=ft.Column(
                spacing=8,
                controls=[
                    ft.Text(mode.name, weight=ft.FontWeight.BOLD),
                    ft.Button(
                        "Check support",
                        icon=ft.Icons.CHECK_CIRCLE_OUTLINE,
                        on_click=lambda: page.run_task(check_support),
                    ),
                    status,
                ],
            ),
        )

    page.appbar = ft.AppBar(title="LaunchMode Showcase")
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text(
                        "Check launch-mode support reported by the current platform."
                    ),
                    ft.Row(
                        wrap=True,
                        spacing=12,
                        expand=True,
                        scroll=ft.ScrollMode.AUTO,
                        alignment=ft.MainAxisAlignment.CENTER,
                        controls=[showcase_card(mode) for mode in ft.LaunchMode],
                    ),
                ],
            ),
        )
    )


if __name__ == "__main__":
    ft.run(main)

枚举值 ​

名称类型默认值说明
PLATFORM_DEFAULT—'platformDefault'Platform decides how to open the URL.
IN_APP_WEB_VIEW—'inAppWebView'Load the URL inside an in-app web view.
IN_APP_BROWSER_VIEW—'inAppBrowserView'Load the URL inside an in-app browser view (e.g., custom tabs).
EXTERNAL_APPLICATION—'externalApplication'Pass the URL to another application to handle.
EXTERNAL_NON_BROWSER_APPLICATION—'externalNonBrowserApplication'Pass the URL to a non-browser application to handle.

关注我,学习大模型、大数据、Python等热门技术。