Skip to content

bug: Inconsistent behavior of Control.expand when using page.add vs manual page.views manipulation #6341

@bl1nch

Description

@bl1nch

Duplicate Check

Describe the bug

There is a discrepancy in how the expand property is implemented between the default page root and custom ft.View objects.

When a control with expand=True is added via page.add(), it correctly takes priority over fixed dimensions (like height) and fills the entire available space (both vertically and horizontally).

However, when the same control is placed inside a ft.View (managed via page.views), the expand=True property seems to fail vertically. It only expands horizontally, while the vertical expansion is ignored, and the control stays collapsed or respects a fixed height if provided.

Code sample

Code
import flet as ft


@ft.control
class View(ft.View):
    def init(self):
        self.route = "/"


async def main(page: ft.Page):
    # Try uncommenting these lines to see the difference
    # page.views.clear()
    # page.views.append(View())
    page.add(
        ft.Container(
            height=10,
            expand=True,
            bgcolor=ft.Colors.LIME_50
        )
    )


if __name__ == "__main__":
    ft.run(main)

To reproduce

Expected behavior

expand=True should consistently force the control to fill all available space in its parent container, but it fails to do so vertically within a ft.View.

Screenshots / Videos

Captures Image Image

Operating System

Windows

Operating system details

11

Flet version

0.82.2

Regression

Yes, it used to work in a previous Flet version (please specify the version in additional details)

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions