Skip to content

v1: Generator event handlers #5383

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

Merged
merged 1 commit into from
Jun 20, 2025
Merged

Conversation

FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented Jun 19, 2025

Allow event handlers with yield inside (making them generators) to call auto-update on yield.

Example:

import asyncio
from dataclasses import dataclass

import flet as ft

@dataclass
class AppState:
    counter: float

    async def start_counter(self):
        self.counter = 0
        yield
        for _ in range(0, 10):
            self.counter += 0.1
            yield
            await asyncio.sleep(0.5)


def main(page: ft.Page):
    state = AppState(counter=0)

    page.add(
        ft.ControlBuilder(
            state,
            lambda state: ft.Column(
                [
                    ft.ProgressBar(state.counter),
                    ft.Button("Run!", on_click=state.start_counter),
                ]
            ),
        )
    )

ft.run(main)
Screen.Recording.2025-06-19.at.2.23.13.PM.mov

Summary by Sourcery

Enable generator event handlers (sync and async) to drive incremental UI updates by yielding, and fix the auto_update target to reference controls by index.

New Features:

  • Support async and sync generator event handlers to trigger auto-update on each yield.

Bug Fixes:

  • Correct the target passed to auto_update to use the control index reference.

@FeodorFitsner FeodorFitsner merged commit b587398 into v1 Jun 20, 2025
3 checks passed
@FeodorFitsner FeodorFitsner deleted the feodor/v1-generator-handlers branch June 20, 2025 01:07
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.

1 participant