Skip to content

Conversation

@FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented Aug 15, 2025

Close #5468

This pull request refactors the icon generation and usage system in the codebase, moving from custom shell scripts and regex-based parsing to a unified Python script with Jinja2 templates. It also updates the way icons are referenced in Dart code, improving maintainability and consistency across both Dart and Python SDKs. Additionally, it removes the dependency on the flet_datatable2 package and updates the .ruff.toml configuration.

Icon generation and usage refactor:

  • Added a new unified Python script ci/generate_icons.py that downloads icon definitions from Flutter, parses them, and generates both Dart and Python icon files using Jinja2 templates. This replaces multiple shell scripts previously used for icon generation.
  • Introduced new Jinja2 templates for generating icon files: ci/templates/material_icons.dart, ci/templates/cupertino_icons.dart, ci/templates/material_icons.py, and ci/templates/cupertino_icons.py. These templates ensure consistent formatting and easier updates. [1] [2] [3] [4]
  • Removed old shell scripts for icon generation: ci/generate_material_icons_dart.sh, ci/generate_material_icons_python.sh, ci/generate_cupertino_icons_dart.sh, and ci/generate_cupertino_icons_python.sh. [1] [2] [3] [4]

Codebase updates for icon usage:

  • Updated all icon-related Dart code (packages/flet/lib/src/controls) to use getIconData and integer-based icon references, ensuring compatibility with the new icon system. [1] [2] [3] [4] [5] [6] [7] [8]
  • Updated exports in packages/flet/lib/flet.dart to use Flutter's built-in CupertinoIcons and Icons instead of custom icon maps. [1] [2]

Dependency and configuration cleanup:

  • Removed the flet_datatable2 package from client/pubspec.yaml and commented out its usage in client/lib/main.dart. [1] [2] [3]
  • Updated .ruff.toml to exclude the ci/templates directory from linting.

Replaces shell scripts with a unified Python script using Jinja2 templates for icon generation. Adds template files and generated icon lists for both Material and Cupertino icons in Dart and Python. Updates Flet core extension to use icon indices instead of codepoints, simplifying icon lookup and usage. Removes legacy generated icon files and updates build scripts to remove '--no-tree-shake-icons' flag.
Wrapped the ft.run(main) call in a __name__ == "__main__" guard to prevent unintended execution when the module is imported.
Copy link
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 @FeodorFitsner, your pull request is too large to review

@FeodorFitsner FeodorFitsner requested a review from Copilot August 15, 2025 20:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a new architecture for icon creation by delegating icon generation to extensions, replacing the previous string-based icon system with a numeric encoding scheme. The change introduces a new IconData base class and restructures icon handling across the Flet codebase.

  • Replaced string-based icon identifiers with numeric encoding using IconData type
  • Implemented icon creation delegation to extensions through new createIconData method
  • Updated all icon-related type annotations from IconValue/IconValueOrControl to IconData/IconDataOrControl

Reviewed Changes

Copilot reviewed 77 out of 83 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sdk/python/packages/flet/src/flet/controls/icon_data.py New IconData base class with numeric encoding and random selection methods
packages/flet/lib/src/flet_extension.dart Added createIconData method for delegating icon creation to extensions
packages/flet/lib/src/utils/icons.dart Updated icon parsing to use numeric codes and extension delegation
Multiple control files Updated type annotations from IconValue to IconData throughout codebase
ci/generate_icons.py New icon generation script using templates and numeric encoding

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Uncommented and enabled flet_datatable2 in main.dart and pubspec.yaml, switching its git ref to 'main'. Updated several other Flet package refs from 'v1' to 'main' and bumped various dependency versions in pubspec.lock for compatibility with Dart >=3.8.0.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Aug 15, 2025

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0800967
Status: ✅  Deploy successful!
Preview URL: https://fd82409a.flet-docs.pages.dev
Branch Preview URL: https://v1-icons-codepoint.flet-docs.pages.dev

View logs

Updated CupertinoIcons and Icons classes to include package_name and class_name metadata via IconData's __init_subclass__ method. This change enables better identification and organization of icon sets within the Flet framework.
Added comments in Dart files to explain icon integer encoding as (set_id << 16 | index). Updated Python docstring to clarify encoding structure: lower 16 bits for icon index and bits 16-24 for set ID, replacing previous code point-based description.
Updated CupertinoIcons and Icons classes to include package_name and class_name arguments in their inheritance. This change clarifies the source and identity of the icon sets for downstream usage.
The 'ci/templates' directory is no longer excluded from Ruff linting in pyproject.toml, allowing lint checks to be performed on files in this directory.
Updated icon construction logic in navigation bar controls to use buildIconOrWidget for consistency. Improved and clarified docstrings for Icon and NavigationBarDestination classes in Python, including parameter explanations and accessibility notes. Refactored theme parsing for switch themes to simplify argument usage. Minor formatting and doc improvements in CupertinoNavigationBar and IconData.
@FeodorFitsner FeodorFitsner merged commit ce5a457 into main Aug 16, 2025
5 checks passed
@FeodorFitsner FeodorFitsner deleted the v1-icons-codepoint branch August 16, 2025 16:42
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.

v1: Move Icons enum from strings to icon codes

3 participants