.agents/skills/imperative-to-declarative-flet/SKILL.md
Port an existing imperative Flet app to “components mode” with @ft.component, hooks, and (optionally) @ft.observable models.
page.render(App) (components mode).page.update() for normal UI updates.@ft.observable for nested app data you mutate in place (boards/lists/cards, drag+drop reorder).ft.use_state for local ephemeral UI state (hover flags, input text, dialog selection).Control/component objects in state; store ids/enums and create controls during render.trolli → trolli-declarative-*).assets/ with the new folder.@ft.component def App(): ....ft.run(lambda page: page.render(App), assets_dir=...)main(page) function before page.render(App), orft.on_mounted(...) (works, but ordering can be less obvious).Appapp.route: str as source of truth.route_change(e) to normalize/redirect/validate routes and set app.routematch app.route (or a derived active_screen) to pick contentroute_change mutates route state; App() render chooses UI based on that state.src/components/*.py.page.update() usageIf a dialog mutates existing controls and calls page.update(), convert it to:
@ft.component dialog content with ft.use_state for error, selected_color, etc.page.show_dialog(ft.AlertDialog(content=DialogContent(...)))assets_dir derived from __file__.flet run, be aware it can set FLET_ASSETS_DIR and override assets_dir=.page.fonts = {"Pacifico": "Pacifico-Regular.ttf"}font_family="Pacifico".Event[Sub] ≠ Event[Base]):
on_click is declared on Button, annotate e as ft.Event[ft.Button] (or use def handler(): ...).TemplateRoute params are dynamic:
raw = getattr(troute, "id", None) then isinstance(raw, str) before int(raw).controls=[*[...], ...] can confuse type checkers with components: