-
Notifications
You must be signed in to change notification settings - Fork 531
v1: Declarative/Reactive approach in Flet #5342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FeodorFitsner
wants to merge
16
commits into
v1
Choose a base branch
from
feodor/v1-reactive
base: v1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+2,558
−1,013
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ndonkoHenri
reviewed
May 29, 2025
ndonkoHenri
reviewed
May 29, 2025
ndonkoHenri
reviewed
May 30, 2025
@@ -95,9 +95,10 @@ def new_post_init(self: T, *args): | |||
|
|||
@dataclass(kw_only=True) | |||
class BaseControl: | |||
_i: int = field(init=False) | |||
_i: int = field(init=False, compare=False) | |||
_c: str = field(init=False) | |||
data: Any = skip_field() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at skip_field
's definition, this will mean,
data: Any = field(default=None, repr=False, compare=False, metadata={"skip": True})
repr=False
: why shouldn't this prop appear inprint
s ?compare=False
: will this mean that 2 Controls with differentdata
values will pass the==
check? I dont think it should be the case.
Test Code:
from dataclasses import dataclass, field
@dataclass(kw_only=True)
class Example:
name: str = "henri"
data: int = field(default=None, repr=False, compare=False)
a = Example(data=10)
b = Example(data=20)
# repr only includes 'name'
print(a) # Example(name='henri')
# Comparison uses only 'name'
print(a == b) # True (though different 'data')
Suggestion:
data: Any = field(default=None, metadata={"skip": True})
commit 345d6ee Author: Feodor Fitsner <[email protected]> Date: Sat Jun 7 17:46:06 2025 -0700 Flutter 3.32.2 commit 91e657b Author: Feodor Fitsner <[email protected]> Date: Sat Jun 7 12:49:34 2025 -0700 Object patcher fixes. Navigation controls fixed. commit bc3f289 Author: Feodor Fitsner <[email protected]> Date: Fri Jun 6 11:37:53 2025 -0700 OptionalEventCallable allow handlers with `e` arg and without commit eec74c1 Author: Feodor Fitsner <[email protected]> Date: Fri Jun 6 11:30:41 2025 -0700 Fix dart tests commit 4e33aa0 Author: Feodor Fitsner <[email protected]> Date: Fri Jun 6 11:15:40 2025 -0700 Remove Center control commit f00506a Author: Feodor Fitsner <[email protected]> Date: Fri Jun 6 11:00:32 2025 -0700 One more test and cleanup commit 2f0e3ba Author: Feodor Fitsner <[email protected]> Date: Fri Jun 6 10:55:44 2025 -0700 All python tests are passing commit 3aede43 Author: Feodor Fitsner <[email protected]> Date: Thu Jun 5 17:08:15 2025 -0700 Fix mount/unmount for frozen controls commit f4d14a0 Author: Feodor Fitsner <[email protected]> Date: Thu Jun 5 14:05:43 2025 -0700 NEW Control.update and Control.applyPatch methods commit decc499 Author: Feodor Fitsner <[email protected]> Date: Thu Jun 5 09:40:01 2025 -0700 Python part done commit 796f4c4 Author: Feodor Fitsner <[email protected]> Date: Thu Jun 5 08:53:14 2025 -0700 operation path is always two elements commit 96b1fb4 Author: Feodor Fitsner <[email protected]> Date: Wed Jun 4 19:55:20 2025 -0700 Frozen tests passing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a declarative/reactive approach to building UIs in Flet. Developers can now mix imperative and declarative patterns in the same app, enabling more flexible and functional UI code.
Declarative "Counter" example
Declarative Form example
New features & concepts
Frozen controls
Frozen controls are immutable — they must be re-created via constructors. Their properties cannot be updated after creation. Flet uses deep structural comparison to detect changes in frozen controls and determine whether they need to be re-rendered.
@data_view
decoratorIntroduces a "UI as a function of state" paradigm.
A function decorated with
@data_view
accepts one or more inputs (state/data) and returns a Control or a list of Controls. The returned controls are frozen and eligible for diffing and caching.Example:
When the underlying
users
list changes, the developer is responsible for re-invoking theusers_list()
function to generate a new control tree:list_key
propertyThe
list_key
parameter helps Flet identify and match items across control lists when comparing old and new frozen control trees. If two controls in the same list share the samelist_key
, Flet performs a deep comparison to detect changes. This improves performance and preserves state during updates.If
list_key
is omitted orNone
, comparison is done by position and structure.ControlBuilder
controlControlBuilder
is a lightweight reactive control that rebuilds its content every time the UI is updated.Constructor:
state
: any data object.builder
: a function that takesstate
and returns aControl
.See Counter example above.
Other changes
Event handlers without
e
Simple event handlers can now omit
e
parameter, for example both of these work:or