主题
所有被废弃的 API 已移除
概述
Flet 1.0.0 移除了此前各 Flet 版本中所有被废弃的 API,因此这个版本没有任何废弃项残留。每一次移除都有直接的替代方案。
控件与类型
| 已移除 | 替代方案 |
|---|---|
ElevatedButton | [Button][flet.Button] |
ConstrainedControl | [LayoutControl][flet.LayoutControl] |
DragTargetEvent.x / .y | DragTargetEvent.local_position |
DragTargetEvent.offset | DragTargetEvent.global_position |
Video.show_controls | 将 Video.controls 设为 None 来隐藏它们 |
Video.playlist_add() / .playlist_remove() | 直接修改 Video.playlist,例如 append() / pop() |
Colors.BLACK12、Colors.WHITE70、…… | 带下划线的名称,例如 Colors.BLACK_12、Colors.WHITE_70 |
页面与应用 API
| 已移除 | 替代方案 |
|---|---|
app() / app_async() | run() / run_async() |
run() / run_async() 的 target 参数 | main |
Page.go() | Page.push_route() |
Page.launch_url() | UrlLauncher().launch_url() |
Page.can_launch_url() | UrlLauncher().can_launch_url() |
Page.close_in_app_web_view() | UrlLauncher().close_in_app_web_view() |
Page.url_launcher | UrlLauncher() |
Page.browser_context_menu | BrowserContextMenu() |
Page.shared_preferences | SharedPreferences() |
Page.clipboard | Clipboard() |
Page.storage_paths | StoragePaths() |
FletApp.show_app_startup_screen | FletApp.boot_screen_options |
FletApp.app_startup_screen_message | FletApp.boot_screen_options |
工具与配置
| 已移除 | 替代方案 |
|---|---|
flet build 与 flet debug 的 --clear-cache 标志 | flet clean 命令 |
[tool.flet.app.boot_screen] / [tool.flet.app.startup_screen] | 具名屏幕的 [tool.flet.boot_screen] |
Dart 空字符串("")控件状态键 | "default",或 ControlState.DEFAULT |
DropdownM2 没有被移除。它为了 Dropdown 而被废弃的决定已撤销,它仍是一个受支持的控件。
背景
Flet 的兼容性策略会在三个次版本之后移除被废弃的 API。与其把这些移除分散到多个 0.8x 版本里,不如在 1.0.0 中一并处理,让第一个稳定版本不背任何废弃债,也不需要兼容性补丁。
上面列出的每个 API 在此版本之前都会发出运行时 DeprecationWarning,并在 API 文档中带有废弃标签,因此在 0.86 上运行时没有任何警告的代码无需改动。
迁移指南
先在你的应用运行于 Flet 0.86 时,修掉所有发出 DeprecationWarning 的地方——这就是 1.0.0 所移除的完整清单。要看到这些警告,请在启用警告的情况下运行 Python:
bash
python -W default::DeprecationWarning main.py然后套用上表中的替代方案。
迁移前代码:
python
import flet as ft
async def main(page: ft.Page):
async def open_site(e):
await page.launch_url("https://flet.dev")
page.add(ft.ElevatedButton("Open", on_click=open_site))
await page.go("/home")
ft.app(target=main)迁移后代码:
python
import flet as ft
async def main(page: ft.Page):
async def open_site(e):
await ft.UrlLauncher().launch_url("https://flet.dev")
page.add(ft.Button("Open", on_click=open_site))
await page.push_route("/home")
ft.run(main)这三项移除各自有独立的指南,是在 API 被废弃时编写的:
时间线
- 移除于:
1.0.0
参考
- API 文档:[
Button][flet.Button]、[LayoutControl][flet.LayoutControl]、[UrlLauncher][flet.UrlLauncher]、[Colors][flet.Colors] - 兼容性策略
- 问题与 PR:#6693
- 发布说明:Flet 1.0.0