Implement a Flet extension around an external Flutter package using existing flet_* packages as implementation templates.
Inputs
- Control/service name and Python package name (
flet_<extension>). - Target pub.dev package and intended version/range.
- API surface to expose in Python (properties, methods, events, types/enums).
Third-party Dependency Gate
- Confirm package health: maintenance activity, null-safety, platform support, and open issue risk.
- Confirm license is compatible with Flet distribution.
- Confirm that the parts of the package the extension uses don't build widgets from the Flutter SDK's
package:flutter/material.dartorpackage:flutter/cupertino.dart, or take or return their types. Parts it doesn't use don't matter:shadcn_ui'sShadAppis built on the SDKMaterialApp, but flet-shadcn-ui never uses it. Flet renders with thematerial_uiandcupertino_uipackages, so SDKTextField,InkWell,ListTileand similar widgets fail at runtime ("No Material widget found"), and SDKThemeData/ButtonStylevalues don't type-check against Flet's helpers. Prefer a release built onmaterial_ui/cupertino_uior onwidgets.dartonly. - Select a conservative version strategy:
- Pin exact version when behavior stability is critical.
- Use bounded ranges when required by ecosystem constraints.
- Record key constraints and reasons in PR notes/commit message.
Control/Service Classification
- Classify wrapped functionality before implementation:
LayoutControlfor visual controls that participate in page/layout positioning.- Base
Controlfor simple visual controls that do not require page positioning or define their own positioning rules/props (for exampleDraggable,Divider,MenuBar,NavigationRail). - Non-visual Service when functionality is not a renderable UI control.
- Inspect the wrapped Flutter package API to determine whether it includes non-visual/service functionality.
- For service patterns, follow existing extension examples:
sdk/python/packages/flet-audio,sdk/python/packages/flet-flashlight,sdk/python/packages/flet-secure-storage.
API Mapping Rules
- Expose only stable and useful features first; avoid mirroring every upstream option.
- Keep Python API idiomatic and concise; avoid redundant control-name prefixes.
- Map upstream naming inconsistencies to Flet conventions when needed.
- Add custom enums/types only when they improve correctness and discoverability.
Python-side Rules
- Use
LayoutControl, baseControl, or Service base class according to classification. - Implement typed properties, methods, and events exactly for chosen public API.
- Reuse existing serialization/event patterns from sibling controls/services.
Flutter-side Rules
- Import
package:material_ui/material_ui.dart(andpackage:cupertino_ui/cupertino_ui.dartfor Cupertino), neverpackage:flutter/material.dartorpackage:flutter/cupertino.dart. Files that use no Material or Cupertino API importpackage:flutter/widgets.dart. Addmaterial_ui(andcupertino_uiif used) to the extension'spubspec.yamlwith the same constraints aspackages/flet/pubspec.yaml. - Use
parseEnum()for enums — it's exported frompackage:flet/flet.dart. Call it asparseEnum(MyEnum.values, widget.control.getString("attr"), MyEnum.defaultVal)!. Do NOT write a custom_parseXxx()switch helper. - For control attributes, prefer
widget.control.getBool()/getDouble()/...accessors. - For non-control parsing, use shared
parseSomething()helpers. - Do not add one-off private parser utilities when standard helpers exist.
- Put control-specific helpers in
utils/<control>.dart; shared helpers inutils/<topic>.dart. - Prefer
parse-prefixed helper names when converting input to Flutter structures. - Avoid single-use local variables.
- When wrapping a widget in conditional decoration (a label or error text that appears and disappears), keep the widget tree the same shape (always wrap, key the children). Otherwise toggling the decoration rebuilds the inner widget and drops its state, for example focus while typing. Don't decorate by putting the widget in a
Column: it loosens a fixedwidth, which shrinks button-like widgets.
Default Value Matching (Critical)
Properties with default values on the Python side are not sent to Flutter when unchanged from the default. Every Dart property read must provide the same default as its Python counterpart:
control.getDouble("size", 100.0)!when Python hassize: float = 100.0control.getBool("animate", true)!when Python hasanimate: bool = TrueparseDuration(value["dur"], const Duration(milliseconds: 500))!when Python hasdur: DurationValue = field(default_factory=lambda: Duration(milliseconds=500))control.get<List>("items")?.map(...).toList() ?? const []when Python hasitems: list[str] = field(default_factory=list)
Without matching defaults, Dart receives null and either crashes or silently uses the wrong value. This applies to all property types: bools, numbers, strings, enums, durations, collections, and nested @ft.value types.
Integration Checklist
- Register in the Flet client app — two files:
1. client/pubspec.yaml: add flet_<ext>: path: ../sdk/python/packages/flet-<ext>/src/flutter/flet_<ext> under dependencies.
2. client/lib/main.dart: add import 'package:flet_<ext>/flet_<ext>.dart' as flet_<ext>; and flet_<ext>.Extension() to the extensions list.
- Add extension package to
sdk/python/pyproject.tomlin two places: thedependencieslist and[tool.uv.sources]as{ workspace = true }. - Add extension to
sdk/python/packages/flet/pyproject.tomlin the[dependency-groups] extensionslist. - Add extension to
sdk/python/examples/apps/flet_build_test/pyproject.tomlin three places:[project] dependencies,[tool.uv.sources]as{ path = "...", editable = true }, and[tool.flet.dev_packages]as a relative path string. - Add extension to
tools/crocodocs/pyproject.tomlunder[tool.crocodocs.packages]as<pkg_name> = "../../sdk/python/packages/<pkg-dir>/src". This fixes "Missing API entry" errors in the docs. Note:api-data.jsonis gitignored (generated at build time); only thepyproject.tomlchange needs committing. - Add extension to
.github/workflows/ci.ymlin both places: build_flet_extensions->PACKAGESlist.py_publish->for pkg in ...publish loop.- Add the extension's PyPI name to
FLET_PACKAGESinsdk/python/packages/flet-cli/src/flet_cli/utils/project_dependencies.py, soflet build,flet debugandflet publishpin it to the Flet CLI version. A test fails if a folder insdk/python/packagesis missing from it. - Add
.gitignoreto Flutter extension project if missing. - Remove
[tool.uv.sources]local path overrides from examplepyproject.tomlfiles before opening a PR (they are development-only conveniences).
Docs, Examples, Tests
- Add control/service docs under
website/docs/controls/<name>for controls andwebsite/docs/services/<name>for services. - Always create one doc page per control, even for extensions with many similar controls. Use
index.mdfor the overview (install instructions, examples, list of links) and individual<controlname>.mdfiles for each control — consistent withflet-color-pickersand other extensions. - Use
<ClassSummary name="pkg.ClassName" />and<ClassMembers name="pkg.ClassName" />JSX from@site/src/components/crocodocsto render API docs. - Give sub-controls their own page too. A sub-control is a control that can only be used inside a specific parent control (e.g.
TableColumn/TableRow/TableCellinTable,MenuIteminContextMenu/Menubar,RadioinRadioGroup,TabinTabs,AccordionIteminAccordion), not any control placed in another'scontrols/content. Never render a second class's<ClassSummary>/<ClassMembers>on the parent's page: each page must document exactly one class, otherwise it gets two "Properties"/"Events" headings with the same anchor and the table of contents breaks. - Sub-control page: front matter
class_nameandtitle, then<ClassSummary name={frontMatter.class_name} />and<ClassMembers name={frontMatter.class_name} />(no example/images needed); file name is the lowercased class name (tablecolumn.md). - Nest sub-control pages under their parent in
website/sidebars.yml(Table: {_index: .../table.md, TableColumn: .../tablecolumn.md, ...}), like coreDataTable → DataCell. A sub-control shared by several parents (e.g.MenuItemforContextMenuandMenubar) is listed once, under one parent. - Make sure each parent page links to its sub-controls: reference them with
:class:roles in the parent's docstrings (class description or the property that holds them, e.g.items), which render as links to the sub-control page. - Include screenshots in the docs for every visual control (see "Example Tests and Docs Images" below). Only omit
image=/imageCaption=/imageWidth=on<ClassSummary>for non-visual services or controls that cannot be screenshotted (continuously animating ones). - In the
## Examplessection, do NOT add###subtitles above<CodeExample>blocks — titles are injected automatically from the example file itself. - Add all custom enums/types docs and update
website/sidebars.ymlnavigation. List new extension controls underReference → Controls → Extensions(alphabetically). Only an extension that brings its own design system gets its own folder next to Core/Material/Cupertino/Extensions, likeShadcn. See the "Sidebar Navigation" section of.agents/skills/docs-conventions/SKILL.md. - Use markdown filenames without underscores (
codeeditor.md, notcode_editor.md). - Add examples under
sdk/python/examples/extensions/<name>/for extension controls. - Use
import flet_<ext> as <short_alias>in examples (e.g.,import flet_spinkit as spins). Keep alias short but readable. - Use
ft.Colors.SURFACE_CONTAINER_HIGHESTfor card/cell backgrounds in showcase examples — it adapts to light and dark system themes automatically. - Do NOT set an explicit dark theme in examples; let the app use system theme (no
page.theme_mode). - Add integration tests under
packages/flet/integration_tests/extensions/<name>/— not inside the extension package's own directory (notests/folder in the package itself, matching the pattern offlet-code-editor,flet-color-pickers, etc.). - For controls with continuously-running animations, do NOT use
assert_control_screenshotorpump_and_settle— they will timeout waiting for animations to settle. Instead useawait flet_app.tester.pump(duration=ft.Duration(milliseconds=500))which advances the clock by a fixed amount. This still runs real Flutter rendering and catches crashes, without screenshot comparison. - Ensure generated screenshots are suitable for docs usage when visual examples are added.
Example Tests and Docs Images
Every example gets an integration test, and the goldens it produces are the docs images. Follow sdk/python/packages/flet/integration_tests/examples/controls/material/test_checkbox.py.
Every docs image must be light and opaque. Screenshots are transparent by default: on the website's dark mode dark text becomes unreadable, and create_gif flattens transparency to black, so flow GIFs come out dark. For every screenshot used in docs:
- set
page.theme_mode = ft.ThemeMode.LIGHT(andpage.update()after launching an example); - pass
bgcolor=ft.Colors.SURFACEtoassert_control_screenshot,wrap_page_controls_in_screenshotandtake_page_controls_screenshot; - after generating, confirm the images (including every frame of each GIF) have a light background, not black or transparent.
- Create one test file per control in
sdk/python/packages/flet/integration_tests/examples/extensions/<name>/test_<control>.py. The file stem picks the golden folder (golden/macos/<control>/), so each control's images stay together. - In each file:
test_image_for_docs(usesflet_app_function): setpage.theme_mode = ft.ThemeMode.LIGHTand callassert_control_screenshot(request.node.name, bgcolor=ft.Colors.SURFACE, control=...)with a compact showcase of the control (a few states/variants). Wrap rows inft.Column(intrinsic_width=True, ...)so the image is not stretched to the page width.- One test per example, parametrized with
{"flet_app_main": example.main}andindirect=True: - set
page.theme_mode = ft.ThemeMode.LIGHTandpage.update()(examples do not set a theme); - interact like a user (
tap,enter_text,mouse_hover) and assert the example's visible result (find_by_text(...).count == 1); - screenshot only the page controls:
take_page_controls_screenshot(bgcolor=ft.Colors.SURFACE)for a single image, orscr = await wrap_page_controls_in_screenshot(bgcolor=ft.Colors.SURFACE)+scr.capture(pixel_ratio=...)for several states; - for multi-step flows, save each state (
<example>_initial,<example>, ...) and combine them withcreate_gif([...], "<example>_flow", duration=1000). enter_textneeds a finder on the input itself, so give example inputs (and other controls the test must target) akey=and usefind_by_key.
- Generate goldens from
sdk/python:FLET_TEST_GOLDEN=1 uv run pytest -s packages/flet/integration_tests/examples/extensions/<name>. Open and review every PNG and GIF (dark or transparent background, stretched rows, cramped spacing, oversized icons, clipping), fix the test or example, regenerate, then re-run withoutFLET_TEST_GOLDENto confirm the comparisons pass. Commit thegolden/macos/<control>/*files. - Reference the images in each control page:
- front matter:
example_images: "test-images/examples/extensions/<name>/golden/macos/<control>"(crocodocs'test-imagesmapping already servesintegration_tests); <ClassSummary name={frontMatter.class_name} image={frontMatter.example_images + '/image_for_docs.png'} imageCaption="<ClassName>" imageWidth="30%"/>, with the width tuned to the image;- under each
<CodeExample>:<Image src={frontMatter.example_images + '/<example>.png'} alt="<example>" width="45%" caption="<what the user did>" />, pointing to the_flow.giffor flows; importImagefrom@site/src/components/crocodocs.
- Run
uv --directory ./tools/crocodocs run crocodocs generatefrom the repo root and check that the images appear underwebsite/static/docs/test-images/...(generated, not committed).
Upgrade and Compatibility Guardrails
- Add at least one test that catches upstream behavioral changes likely to break wrapper mapping.
- Avoid exposing experimental upstream APIs unless explicitly requested.
- Keep wrapper surface narrow enough to maintain backwards compatibility across upstream updates.
Validation
- Run relevant Python and integration tests for touched areas.
- Verify Python import paths, client runtime registration, and docs navigation.
- Verify dependency resolution and lockfile updates are intentional.
Temporary CI narrowing on the feature branch
- While developing an extension, the maintainer may narrow
.github/workflows/macos-integration-tests.ymlon purpose so CI runs only the new extension's tests: theinclude:list of the matrix is cut to one group whosedirslists only the extension's directories (for exampleexamples/extensions/<name>andextensions/<name>). - This is intentional. Do NOT revert, "fix", or restore that matrix while working on the branch, and keep it when committing unless told otherwise.
- Before the branch is merged (when the user says the work is done), restore the original matrix with its three groups. The
apps-extensionsgroup already includes the new tests throughexamples/extensionsandextensions.