interface
from corio import interface
interface is a thin base for Flet UI apps with lifecycle hooks, typed context wiring, and web-app identity defaults.
Main pieces:
Context: typed runtime container aroundflet.PageBase:ft.Columnsubclass with an async constructor (new), routing hooks, identity metadata, and a launch helper- decorators
updateandprogressfor post-action page refresh/progress display
Install:
pip install "corio[interface]" --upgrade
Typical Base Pattern
import flet as ft
from corio import function, interface
class SampleApp(interface.Base[interface.Context]):
@function.ccp
def metadata(cls) -> interface.Metadata:
"""
Return the sample app's manifest metadata.
"""
return interface.Metadata(
name="Sample Studio",
short_name="Studio",
description="An example Flet web application.",
theme_color="#224466",
background_color="#F0F2F4",
)
def __init__(self):
super().__init__(controls=[ft.Text(self.metadata.name)])
if __name__ == "__main__":
SampleApp.launch()
Base.metadata is an @ccp that returns a typed Metadata model. Metadata.name is required; Base supplies the interface class name by default. The optional short_name is an abbreviated label browsers may use where the full name does not fit; omit it to let the browser use name. See the manifest definitions of name and short_name. The model also defines Flet's manifest defaults, including icon entries and the theme_color and background_color fields. Override the property to customize the complete manifest; use ManifestIcon for typed icon entries, or subclass Metadata to add application-specific fields.
Before launch, Base.prep_assets() creates PATH_ASSETS and writes manifest.json there through Corio's Path.write_json(). Its default is corio.paths.paths.assets / "interface"; override PATH_ASSETS when an application needs another directory. The method returns nothing—Base.launch() passes PATH_ASSETS directly to Flet. This model is the source of truth: a previous manifest is replaced at startup, so declare custom fields and icon lists in the metadata override. The directory must be writable while the app starts.
Flet serves files in the assets directory over its bundled web assets. Put custom files under PATH_ASSETS at these exact, case-sensitive paths (relative to that directory) to replace the defaults:
| Asset path | Used for |
|---|---|
favicon.png |
Browser-tab favicon |
icons/loading-animation.png |
Dynamic web app loading image, shown until Flutter draws its first frame |
icons/icon-192.png, icons/icon-512.png |
PWA icons |
icons/icon-maskable-192.png, icons/icon-maskable-512.png |
Maskable Android PWA icons |
icons/apple-touch-icon-192.png |
iOS “Add to Home Screen” icon |
Flet serves a matching file as-is; supply the intended dimensions and maskable artwork yourself. The default Metadata model references the standard Flet icon paths. Override metadata to choose different paths; those files must be present under PATH_ASSETS.
Loading image versus PWA splash screen
icons/loading-animation.png replaces the dynamic website's pre-first-frame loading image; it is not a full-screen splash configuration. An installed PWA's launch splash is generated by the browser/platform from its manifest, icons, and colors. For flet build web, Flet has a separate build-time splash-screen configuration (assets/splash.png or assets/splash.svg).
Base.launch() targets Flet's dynamic runtime. For flet build web, configure build-time identity in [tool.flet] (product, description) and [tool.flet.web] (pwa_short_name, pwa_theme_color, pwa_background_color); build splash settings are separate from the dynamic loading image. See Flet's dynamic web publishing guide, asset guide, and build configuration.
Advanced Pattern
- Override
async def new(cls, page)for async setup (database/session/bootstrap). - Configure
PATH_ASSETSandPATH_UPLOADSfor static/upload handling. - Use tabs/views and route hooks (
route,pop) for multi-view apps. Handlers receive Flet events:route(event: ft.RouteChangeEvent)andpop(event: ft.ViewPopEvent); view-pop details are available onevent.route,event.view, andevent.page. Baseauto-managesFLET_SECRET_KEYwhen missing.
@classmethod
async def new(cls, page):
# async startup work here
self = await super().new(page)
return self
update and progress decorators are useful for callback methods that need guaranteed page refresh and spinner visibility.