Skip to content

Conversation

@ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Oct 23, 2025

Fix #3626

Example

import flet as ft


def main(page: ft.Page):
    page.spacing = 20

    def expand_tile(e: ft.Event[ft.FilledButton]):
        tile.expanded = True

    def collapse_tile(e: ft.Event[ft.OutlinedButton]):
        tile.expanded = False

    page.add(
        ft.Row(
            alignment=ft.MainAxisAlignment.CENTER,
            controls=[
                ft.FilledButton("Expand Tile", on_click=expand_tile),
                ft.OutlinedButton("Collapse Tile", on_click=collapse_tile),
            ],
        ),
        tile := ft.ExpansionTile(
            title=ft.Text("I am the title of this tile.", weight=ft.FontWeight.BOLD),
            subtitle=ft.Text("This is the subtitle."),
            affinity=ft.TileAffinity.LEADING,
            controls=[ft.Text("👻", size=80)],
            expanded=True,
            on_change=lambda e: print(
                f"Tile was {'expanded' if e.data else 'collapsed'}"
            ),
        ),
    )


ft.run(main)

Summary by Sourcery

Enable programmatic control of ExpansionTile expansion state and customizable animation behavior.

New Features:

  • Introduce an "expanded" property on ExpansionTile for programmatic expand/collapse.
  • Add "animation_style" property and AnimationStyle.no_animation() to customize or disable expand/collapse animations.
  • Expose on_change event data as a boolean reflecting the tile’s expanded state.

Bug Fixes:

  • Fix default selected_index handling and change-event logic in CupertinoSlidingSegmentedButton control.

Enhancements:

  • Refactor Dart ExpansionTileControl to a StatefulWidget with an ExpansibleController for safe state updates.
  • Augment Python and Dart documentation and examples with sections on programmatic expansion/collapse and custom animations.
  • Provide detailed docstrings for TileAffinity, theme properties, and internal control fields.

@ndonkoHenri ndonkoHenri requested a review from Copilot October 23, 2025 03:46
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.

We've reviewed this pull request using the Sourcery rules engine

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 adds programmatic expansion/collapse functionality to the ExpansionTile control by introducing an expanded property, replacing the previous initially_expanded property which only set the initial state. The implementation includes animation customization support and comprehensive documentation updates.

  • Adds expanded property to control tile state programmatically
  • Introduces animation_style property for customizing expansion/collapse animations
  • Updates documentation with examples and enhanced property descriptions

Reviewed Changes

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

Show a summary per file
File Description
sdk/python/packages/flet/src/flet/controls/material/expansion_tile.py Adds expanded and animation_style properties, replaces initially_expanded, enhances documentation, and adds validation for CrossAxisAlignment.BASELINE
packages/flet/lib/src/controls/expansion_tile.dart Converts to StatefulWidget with ExpansibleController to manage programmatic expansion state
sdk/python/packages/flet/src/flet/controls/animation.py Adds AnimationStyle class documentation and no_animation() static method
sdk/python/packages/flet/src/flet/controls/theme.py Adds theme properties for ExpansionTile and ListTile including animation_style, shape, collapsed_shape, affinity, style, and title_alignment
sdk/python/examples/controls/expansion_tile/programmatic_expansion.py New example demonstrating programmatic tile expansion/collapse
sdk/python/examples/controls/expansion_tile/custom_animations.py New example showing custom animation styles for expansion tile
sdk/python/packages/flet/docs/controls/expansiontile.md Adds documentation sections for programmatic expansion and custom animations
packages/flet/lib/src/utils/theme.dart Updates theme parsers to support new ExpansionTile and ListTile theme properties
sdk/python/packages/flet/src/flet/controls/material/text_button.py Minor documentation wording improvement
sdk/python/packages/flet/src/flet/controls/material/expansion_panel.py Minor documentation wording improvement
sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_sliding_segmented_button.py Simplifies documentation and reorders example property
packages/flet/lib/src/controls/cupertino_sliding_segmented_button.dart Minor code formatting and logic simplification
sdk/python/packages/flet/src/flet/controls/base_control.py Adds internal documentation for _internals field

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

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 23, 2025

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5b496f0
Status: ✅  Deploy successful!
Preview URL: https://37bb4812.flet-docs.pages.dev
Branch Preview URL: https://expansion-tile-feat.flet-docs.pages.dev

View logs

@FeodorFitsner
Copy link
Contributor

Please fix tests: https://github.com/flet-dev/flet/actions/runs/18736961772
Add tests for introduced/changed functionality:

  1. ExpansionTile.expanded = True/False
  2. ListTileTheme - new props

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.

ExpansionTile Expand programmatically

2 participants