Skip to content

Migrate examples to projects#6355

Open
InesaFitsner wants to merge 101 commits intomainfrom
migrate-examples-to-projects
Open

Migrate examples to projects#6355
InesaFitsner wants to merge 101 commits intomainfrom
migrate-examples-to-projects

Conversation

@InesaFitsner
Copy link
Copy Markdown
Contributor

Description

Test Code

# Test code for the review of this PR

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • I signed the CLA.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing tests pass locally with my changes
  • I have made corresponding changes to the documentation (if applicable)

Screenshots

Additional details

Refactor chip examples into package folders (assist_chips, filter_chips): add main.py and __init__.py, add pyproject.toml metadata for each example, and wrap UI in SafeArea/Column where appropriate. Remove the old top-level assist_chips.py and filter_chips.py scripts. Update docs to reference the new example paths (assist_chips/main.py and filter_chips/main.py). Also minor code tweaks: simplified click handlers (removed explicit page.update and adjusted handler implementations) and a placeholder pass for amenity selection handler.
Introduce a new .codex skill describing how to convert flat Flet example .py files into standalone example projects. The guide defines required project layout (main.py, pyproject.toml, assets/, __init__.py), metadata inference rules, dependency inference, mobile-safety recommendations, docs/tests update steps, and validation/checklist commands to ensure correct migration and indexing for Gallery/MCP.
Remove example package __init__.py files and switch tests/docs to import example modules directly. Updated SKILL.md to instruct creating example projects without __init__.py and adjusted test_checkbox imports to use module-level imports (e.g. import examples.controls.checkbox.basic as basic). Deleted: sdk/python/examples/controls/checkbox/__init__.py, sdk/python/examples/controls/chip/__init__.py, sdk/python/examples/controls/chip/assist_chips/__init__.py, sdk/python/examples/controls/chip/filter_chips/__init__.py; modified .codex/skills/create-flet-example-projects/SKILL.md and sdk/python/packages/flet/integration_tests/examples/material/test_checkbox.py to match the new import approach.
Replace the no-op handler with a print statement so the example logs the selected amenity when a Chip is activated. This demonstrates event handling by printing the chip's label (e.control.label.value) to the console for debugging and instructional purposes.
Move checkbox example scripts into per-example main.py files and add pyproject.toml metadata for basic, handling_events, and styled examples. Update docs to reference the new example paths and adjust integration test imports to point to the new modules. Also tweak a gallery category in filter_chips pyproject.toml. These changes standardize example layout and provide per-example metadata for the gallery/tooling.
Expand and clarify the SKILL.md for creating Flet example projects: add support for migrating flat examples and normalizing mixed/partially converted folders, detect example states (flat file, project folder, mixed), and adjust the workflow to convert/repair examples without overwriting existing main.py. Add guidance to create or update pyproject.toml metadata, avoid unnecessary edits to already-converted examples, preserve media/asset handling, and enhance validation steps (compile changed main.py, search for stale paths, run targeted integration tests when present). Also clarify import conventions (no __init__.py) and when to update references to avoid churn.
Remove unnecessary explicit page.update() calls from checkbox examples to avoid redundant UI refreshes. The changes update sdk/python/examples/controls/checkbox/basic/main.py and sdk/python/examples/controls/checkbox/handling_events/main.py — cleaning up minor, non-functional code and relying on the framework's automatic update handling.
Move column example scripts into per-example folders (rename *.py to */main.py) and add per-example pyproject.toml metadata for column examples (alignment, custom_scrollbar, horizontal_alignment, infinite_scrolling, programmatic_scroll, scroll, scroll_events, scroll_to_key, spacing, wrap). Update docs (controls/column.md) to reference new example paths. Also adjust gallery categories in several example pyproject.toml files for checkbox and chip examples (simplify categories to Input/Checkbox or Input/Chip) to keep gallery metadata consistent.
Update SKILL.md to prefer using @ft.control for custom Flet controls and recommend moving constructor setup to declarative fields + init(). Convert two example projects (column/alignment and column/horizontal_alignment) to the new pattern: add @ft.control, replace __init__ with a declarative alignment field and init() method, use self.alignment in controls, and update example instantiations to use the alignment= keyword. Also renumbered the validation step in SKILL.md. These changes keep behavior identical while aligning examples with the preferred control style.
Wrap multiple Python Column example pages in ft.SafeArea so their UI respects device safe areas. Refactor layout nesting by moving Row/Column/Container controls into the SafeArea content (improves padding and layout consistency). Updated examples: alignment, custom_scrollbar, horizontal_alignment, infinite_scrolling, programmatic_scroll, scroll, scroll_events, scroll_to_key, spacing, and wrap.
Clarify mobile-safety guidance: apply the SafeArea requirement to all examples in the touched folder (new, migrated, and already converted), not just files changed by moves. Add validation to confirm every <example>/main.py in scope wraps rendered content in a top-level ft.SafeArea so examples render correctly on mobile.
Wrap ft.run(main) calls with if __name__ == "__main__": in column examples to prevent running examples on import (applies to multiple files under sdk/python/examples/controls/column). Also set SafeArea expand=True in the scroll example to ensure it fills available space for proper layout.
Add a new checklist item requiring every example main.py to end with an if __name__ == "__main__": ft.run(main) entrypoint and apply it to new, migrated, and already-converted examples. Adjust numbering for subsequent items (Update references → 9, Validate → 10) and expand validation to compile changed main.py files and confirm top-level ft.SafeArea wrapping plus the ft.run(main) entrypoint. Keep existing guidance on updating docs/tests references and avoiding unnecessary churn.
Rename and reorganize the AlertDialog example: move modal_and_non_modal.py to modal_and_non_modal/main.py and remove the package __init__.py. Wrap example buttons in a SafeArea/Column. Add a pyproject.toml for the example with gallery and metadata (title, controls, layout_pattern, etc.). Update docs to reference the new example path and adjust the integration test import accordingly. Also replace the golden GIF asset (updated visual).
Restructure animated_switcher examples: move example scripts into example-specific main.py entrypoints, add pyproject.toml metadata for each example, and wrap example UIs in SafeArea/Column. Refactor the buffered image switcher: mark as @ft.control, use typed image fields and a default_factory-backed image_queue, initialize content in init, improve async preloading and base64 handling, and update how the control is instantiated. Add guarded ft.run(main) entrypoints instead of unconditional runs. Update documentation references to point to the new example/main.py paths and remove the old top-level example files.
Refactor BufferingSwitcher to use a 'content' attribute instead of 'image'. Updated attribute name, initialization checks, and queue append logic to reference 'content', removed the redundant assignment from 'image' to 'content', and updated the example instantiation in main() to pass content=ft.Image(...). This clarifies intent and avoids confusion between the control and its inner Image instance.
Rename AppBar example scripts into standalone project folders (moved to .../actions_and_popup_menu/main.py and .../theme_and_material_mode_toggles/main.py) and add corresponding pyproject.toml files. Wrap example UI in ft.SafeArea, remove unnecessary page.update() calls, and add a proper if __name__ == "__main__": ft.run(main) entrypoint. Update docs (appbar.md) to reference the new example paths. Update SKILL.md to enforce the page.update() rule for all examples in the touched folder and to require validation of SafeArea and entrypoints.
Remove unnecessary explicit page.update() calls from example scripts to avoid extra UI refreshes. Deleted calls in sdk/python/examples/controls/animated_switcher/image_switch/main.py and sdk/python/examples/controls/column/scroll/main.py (add/remove textbox handlers and change_scroll). These rely on the framework's automatic updates, so the explicit calls were redundant.
Introduce a 'Code style' section in the skill docs to enforce consistent argument ordering for wrapped controls (keep content= or controls= as the last named argument) and require adherence to the repository's Ruff linting rules in pyproject.toml. This ensures consistent formatting when creating or refactoring standalone Flet example projects.
Remove deprecated Material 3 toggle from the AppBar theme example and rename the example to focus on theme mode only. Changes: removed use_material3 flags and the material-mode toggle UI/logic from example main.py, simplified theme initialization, updated example package metadata (pyproject.toml) to remove Material 3 references and adjust name/description/keywords/features, renamed example path from theme_and_material_mode_toggles to theme_mode_toggle, and updated docs (appbar.md) to point to the new example and title. Also updated the SKILL checklist to require removal of use_material3 and related validation steps.
Rename and restructure the AutoComplete example: move basic.py to basic/main.py, wrap the AutoComplete control in SafeArea and Column (placing the info Text alongside it) and add a standard if __name__ == "__main__" guard for ft.run. Add a pyproject.toml for the example with project metadata, dependencies, and tool.flet gallery metadata. Update the autocomplete docs include to point to the new basic/main.py path.
Reorganize Python example files: replace example root scripts with main.py entrypoints and add per-example pyproject.toml metadata. AutofillGroup example moved to basic/main.py, wrapped in SafeArea, added __main__ guard and new pyproject. Badge example renamed to basic/main.py (removed package __init__.py), minor layout change wrapping body in SafeArea/Column, and added its pyproject. Update docs to point to "basic/main.py" paths and update integration test import to import examples.controls.badge.basic.main. Remove obsolete files from the previous layout.
Refactor example files: rename example scripts to main.py (banner/basic, bottom_app_bar/border_radius, bottom_app_bar/notched_fab), wrap example page content in SafeArea/Column and guard ft.run with if __name__ == "__main__". Add pyproject.toml metadata for each example (banner-basic, bottom-app-bar-border-radius, bottom-app-bar-notched-fab). Remove bottom_app_bar __init__.py and update docs and integration test imports to reference the new example paths.
Move bottom_sheet example scripts into per-example subpackages (basic/main.py, fullscreen/main.py) and remove the old top-level files. Wrap example BottomSheet contents with SafeArea to handle intrusions, add pyproject.toml metadata for both examples (gallery, controls, features), and remove the examples __init__.py. Update docs examples includes to point to the new main.py paths and adjust integration test imports accordingly. Golden example images were also updated.
Remove SafeArea wrapper from BottomSheet content and simplify sheet to use a Container with padded Column. Add a SafeArea around the page controls (Display button + Fullscreen switch) instead. Update golden assets (GIF/PNGs) for macOS bottom_sheet fullscreen to reflect the visual/layout changes.
Move button example scripts into per-example directories (each with main.py and pyproject.toml), remove the old top-level example .py files, and wrap example UI content in SafeArea/Column. Update docs to reference the new example paths (e.g. examples/*/main.py) and adjust integration test imports to import the new modules. Adds metadata for gallery packaging and keeps example behavior unchanged.
Rename ads and camera example modules to example_1/main.py, add pyproject.toml metadata for both examples (gallery metadata, deps and platforms), and update docs to reference the new example paths. Also wrap ads example buttons in SafeArea and protect ft.run with an if __name__ == "__main__" guard.
Refactor canvas example files into per-example packages: rename .py examples into <example>/main.py, add pyproject.toml metadata for each example, and update docs references. Wrap example UIs in SafeArea, add proper if __name__ == "__main__" run guards, and make small layout tweaks (e.g. brush container -> Column + SafeArea, comment out disable_auto_update). Remove the old top-level example scripts and update the canvas docs to point to the new main.py paths.
Move Tabs examples into dedicated example packages (basic, custom_indicator, dynamic_tab_addition, move_to, nested): delete old top-level example .py files and add per-example main.py and pyproject.toml files. Examples now wrap content in SafeArea and include metadata (pyproject) for gallery listing. Dynamic tab example updated to use @ft.control-style component fields for MyContainer. Update docs (packages/flet/docs/controls/tabs/index.md) to point to the new ".../main.py" example paths.
Reorganize Python UI examples by replacing flat example scripts with per-example packages: deleted legacy example files and added main.py and pyproject.toml in each example folder (controls/text/* and controls/text_button/*). UI layouts are wrapped with SafeArea/Column, and each example now includes package metadata for the Flet gallery. Update docs to reference the new example paths and adjust integration test imports to the new module locations.
Move TextField example scripts into per-example directories (each now provides main.py) and add pyproject.toml metadata for each example. Legacy flat example files were removed, UI containers were standardized (SafeArea/Column where appropriate), and documentation links in textfield.md were updated to point to the new example paths.
Move example scripts into per-example main.py entrypoints and add pyproject.toml metadata for gallery/tests. Wrap example UIs with SafeArea and refactor layouts (TimePicker: basic/hour_formats/custom_locale, TransparentPointer basic). Remove old flat example files and update docs and tests to reference new paths.
Restructure several Python example packages by moving standalone example scripts into example-specific main.py entrypoints (vertical_divider, webview, window_drag_area, video) and deleting the old top-level example files. Add pyproject.toml metadata for each new example package to support the Flet gallery. Wrap example UIs in SafeArea where appropriate and add a __main__ guard to the video example. Update documentation snippets to reference the new example paths and adjust integration test imports to the new module locations.
Remove the old standalone container.py and add a new example at sdk/python/examples/controls/types/alignment/container/main.py (wrap-enabled Row inside SafeArea/Column). Add pyproject.toml for the example with project and Flet gallery metadata. Update the docs to reference the new examples/container/main.py path.
Move example entrypoints into showcase/main.py (rename showcase.py -> showcase/main.py), wrap example UIs with SafeArea/Column, and replace direct ft.run calls with an if __name__ == "__main__" guard. Add per-example pyproject.toml files with gallery/metadata for many showcases, relocate several container/showcase scripts into new main.py paths, and remove legacy/duplicate files. Also update multiple docs under sdk/python/packages/flet/docs/types to reflect these changes.
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we are unable to review this pull request

The GitHub API does not allow us to fetch diffs exceeding 300 files, and this pull request has 1816

@InesaFitsner InesaFitsner removed the request for review from ndonkoHenri March 29, 2026 23:19
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying flet-examples with  Cloudflare Pages  Cloudflare Pages

Latest commit: 200aa0c
Status: ✅  Deploy successful!
Preview URL: https://d5bd381e.flet-examples.pages.dev
Branch Preview URL: https://migrate-examples-to-projects.flet-examples.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 200aa0c
Status:🚫  Build failed.

View logs

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 200aa0c
Status: ✅  Deploy successful!
Preview URL: https://d54fed6b.flet-docs.pages.dev
Branch Preview URL: https://migrate-examples-to-projects.flet-docs.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants