Skip to content

Observable

Mixin: notifies when fields change; auto-wraps lists/dicts to be observable.

Example: ```python import flet as ft from dataclasses import dataclass

@ft.observable
@dataclass
class MyDataClass:
    x: int
    y: int

obj = MyDataClass(1, 2)

def listener(sender, field):
    print(f"Changed: {field} in {sender}")

obj.subscribe(listener)
obj.x = 3
obj.y = 4
```

方法 ​

名称类型默认值说明
subscribeCallable[[], None]—Register a change listener. Args: fn: Listener callback receiving (sender, field). Returns: A disposer function that unsubscribes the listener.
notify——Manually notify listeners that something changed.

关注我,学习大模型、大数据、Python等热门技术。