Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Lazy loading of icons, theme for faster app startup#6043

Merged
FeodorFitsner merged 12 commits intomainfrom
faster-startup
Jan 21, 2026
Merged

Lazy loading of icons, theme for faster app startup#6043
FeodorFitsner merged 12 commits intomainfrom
faster-startup

Conversation

@FeodorFitsner
Copy link
Contributor

No description provided.

Removed direct imports of Icons and CupertinoIcons from __init__.py and added dynamic attribute access via __getattr__. Updated Dropdown to set default icons in before_update instead of as class attributes. Fixed import of IconData in time_picker.py to use the correct module.
Updated the icon generation script to output both .pyi stubs and JSON files for Material and Cupertino icons. Replaced hardcoded icon values in cupertino_icons.py with dynamic loading from JSON, and added package data configuration in pyproject.toml to include new icon resources.
Moved theme-related imports in __init__.py to dynamic attribute access via __getattr__, reducing upfront imports and improving modularity. Updated type hints in base_page.py and container.py to use TYPE_CHECKING for Theme, ensuring proper type checking without runtime imports.
Introduced a random() method to both CupertinoIcons and Icons proxies, allowing selection of a random icon with optional exclusion and weighting. Also refactored internal value caching and removed unnecessary time measurement from Material icons.
Deleted .github/scripts/templates/cupertino_icons.py and material_icons.py as they are no longer needed. Minor formatting changes in Dart icon lists and updates to Python icon JSON and type stub files for Cupertino and Material icons.
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 larger than the review limit of 150000 diff characters

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 21, 2026

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 674b684
Status: ✅  Deploy successful!
Preview URL: https://a68a0c0c.flet-docs.pages.dev
Branch Preview URL: https://faster-startup.flet-docs.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 21, 2026

Deploying flet-examples with  Cloudflare Pages  Cloudflare Pages

Latest commit: 674b684
Status: ✅  Deploy successful!
Preview URL: https://1405f300.flet-examples.pages.dev
Branch Preview URL: https://faster-startup.flet-examples.pages.dev

View logs

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 pull request implements lazy loading of icons and theme modules to improve app startup performance. The changes defer the import of large icon datasets and theme configurations until they are actually needed.

Changes:

  • Introduced lazy loading pattern for icons in dropdown component using before_update() hook
  • Applied TYPE_CHECKING pattern to avoid circular imports for Theme references in container and base_page
  • Added JSON data files for Material and Cupertino icons for runtime loading
  • Created stub files (.pyi) for type hints without runtime overhead
  • Updated package configuration to include JSON and stub files
  • Configured pre-commit hooks to exclude generated files

Reviewed changes

Copilot reviewed 19 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
sdk/python/pyproject.toml Added ruff exclusion for .github directory
sdk/python/packages/flet/src/flet/controls/material/time_picker.py Changed IconData import to use icon_data module instead of material.icons
sdk/python/packages/flet/src/flet/controls/material/icons.json Added Material icons JSON data (new file with icon mappings)
sdk/python/packages/flet/src/flet/controls/material/dropdown.py Implemented lazy loading of Icons in before_update() method
sdk/python/packages/flet/src/flet/controls/material/container.py Applied TYPE_CHECKING pattern for Theme imports
sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_icons.pyi Added type stub file for Cupertino icons
sdk/python/packages/flet/src/flet/controls/base_page.py Applied TYPE_CHECKING pattern for Theme imports
sdk/python/packages/flet/pyproject.toml Added package data configuration for JSON and stub files
sdk/python/.pre-commit-config.yaml Added exclusion patterns for .github directory
client/windows/flutter/generated_plugins.cmake Added flutter_secure_storage_windows plugin
client/linux/flutter/generated_plugins.cmake Added flutter_secure_storage_linux plugin

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Updated cupertino_icons.pyi and material_icons.pyi templates to remove inheritance from IconData and related class arguments, making the classes plain containers for IconData attributes. Also fixed formatting in Dart icon lists and updated JSON icon files for Python SDK.
Copy link
Contributor

@ndonkoHenri ndonkoHenri left a comment

Choose a reason for hiding this comment

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

lgtm

So, the below changes are always to be applied, right?

  • Theme -> "Theme"
  • icons import in before_update()

@ndonkoHenri
Copy link
Contributor

@FeodorFitsner
Copy link
Contributor Author

lgtm

So, the below changes are always to be applied, right?

  • Theme -> "Theme"
  • icons import in before_update()

Looks like, yeah. Both are heavy things to be imported without necessity.
I'm actually thinking if that's even possible to do everything lazy loaded? :)

Deleted the before_update method that set default trailing icons in the Dropdown control. This change may be part of a refactor to handle icon defaults elsewhere or to simplify the control's logic.
Changed the GitHub Actions runner from macos-15 to macos-26 for the macOS integration tests workflow to use a newer macOS environment.
Updated the PyPI cleanup script to target version 0.81.0.dev and include flet-secure-storage. Added a delay in the test_responsive_row.py custom breakpoint test to improve test stability.
Corrected references in the Image control docstrings from 'placeholder' to 'placeholder_src'. Simplified ResponsiveRow docstrings by removing unsupported alignment notes and the clean() method. Fixed a docstring reference in LayoutControl from 'LayoutControl' to 'Control' for the opacity property.
@FeodorFitsner FeodorFitsner merged commit 5875f98 into main Jan 21, 2026
34 of 59 checks passed
@FeodorFitsner FeodorFitsner deleted the faster-startup branch January 21, 2026 21:43
@yst-one
Copy link

yst-one commented Jan 22, 2026

lgtm 
So, the below changes are always to be applied, right?那么,以下更改总是要应用,对吗?

  • Theme -> "Theme"
  • icons import in before_update()icons 在 before_update() 中导入

Looks like, yeah. Both are heavy things to be imported without necessity.看起来是的。这两项在没有必要的情况下导入都很重。 I'm actually thinking if that's even possible to do everything lazy loaded? :)我其实在想,是否真的可以做到所有内容都懒加载呢? :)
It's so needed.

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.

4 participants