flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
11.61k stars 455 forks source link

fix: `Switch`'s `height` and `width` properties not respected when `label` is set #3998

Closed ndonkoHenri closed 1 month ago

ndonkoHenri commented 2 months ago

Description

Fixes #3997

Continuation of https://github.com/flet-dev/flet/pull/3670

Test Code

import flet as ft

def main(page: ft.Page):
    page.add(
        ft.Switch(
            label="Switch 50",
            value=True,
            on_change=lambda e: print(e.value),
            height=50,
        ),
        ft.Switch(
            label="Switch 100",
            value=True,
            on_change=lambda e: print(e.value),
            height=100,
            label_position=ft.LabelPosition.LEFT,
        ),
    )

ft.app(target=main)

Summary by Sourcery

Fix the issue where the Switch component's height and width properties were not respected when a label was set, ensuring proper layout and functionality.

Bug Fixes:

sourcery-ai[bot] commented 2 months ago

Reviewer's Guide by Sourcery

This pull request addresses an issue where the Switch control's height and width properties were not being respected when a label was set. The fix involves restructuring the widget tree to ensure proper sizing and layout of the Switch control with its label.

File-Level Changes

Change Details Files
Restructured the widget tree for the Switch control with label
  • Wrapped the existing Switch and label widgets in a Row with MainAxisSize.min
  • Moved the MergeSemantics widget to encompass the entire Row
  • Adjusted the order of widgets in the Row based on label position
packages/flet/lib/src/controls/switch.dart

Tips - Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request. - Continue your discussion with Sourcery by replying directly to review comments. - You can change your review settings at any time by accessing your [dashboard](https://app.sourcery.ai): - Enable or disable the Sourcery-generated pull request summary or reviewer's guide; - Change the review language; - You can always [contact us](mailto:support@sourcery.ai) if you have any questions or feedback.