Skip to content

FilledButton and FilledToneButton doesn't respect the style keyword #2268

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

Closed
johnnychen94 opened this issue Dec 26, 2023 · 0 comments · Fixed by #2435
Closed

FilledButton and FilledToneButton doesn't respect the style keyword #2268

johnnychen94 opened this issue Dec 26, 2023 · 0 comments · Fixed by #2435

Comments

@johnnychen94
Copy link
Contributor

johnnychen94 commented Dec 26, 2023

Description

The style keyword is not respected by either the FilledButton or FilledToneButton when setting color and bgcolor values using the new ButtonStyle flavor.

Code example to reproduce the issue:

import flet as ft

def main(page: ft.Page):
    page.bgcolor = ft.colors.BLACK

    btn = ft.FilledButton(
        text="Install",
        style=ft.ButtonStyle(
            bgcolor={
                ft.MaterialState.DISABLED: ft.colors.RED_500,
                "": ft.colors.BLUE_400,
            },
            color={
                "": ft.colors.WHITE,
            },
        ),
        disabled=True,
    )

    page.add(btn)


ft.app(target=main)

Describe the results you received:

image

Describe the results you expected:

The background color should be ft.colors.RED_500 as style specifies.

Additional information you deem important (e.g. issue happens only occasionally):

This one is similar to #1754. I believe the default value passing of FilledButton color/bgcolor/elevation needs to be carefully revisited or redesigned.

I believe this is a bug because it's not consistent with other button types:

image

script to build the screenshot
import flet as ft


def build_button(ButtonType, disabled):
    return ButtonType(
        text="Install",
        style=ft.ButtonStyle(
            bgcolor={
                ft.MaterialState.DISABLED: ft.colors.RED_500,
                "": ft.colors.BLUE_400,
            },
            color={
                "": ft.colors.WHITE,
            },
        ),
        disabled=disabled,
    )


def build_button_row(ButtonType):
    btn = build_button(ButtonType, disabled=False)
    btn_disabled = build_button(ButtonType, disabled=True)
    return ft.Row([ft.Text(f"{ButtonType}:"), btn, btn_disabled])


def main(page: ft.Page):
    page.bgcolor = ft.colors.BLACK

    rows = []
    for btnType in [
        ft.ElevatedButton,
        ft.FilledButton,
        ft.FilledTonalButton,
        # ft.FloatingActionButton, # `style` keyword not supported
        ft.TextButton,
        ft.OutlinedButton,
    ]:
        rows.append(build_button_row(btnType))

    page.add(ft.Column(rows))


ft.app(target=main)

Flet version (pip show flet):

❯ poetry show | grep flet

flet                  0.17.0       Flet for Python - easily build interacti...
flet-core             0.17.0       Flet core library
flet-runtime          0.17.0       Flet Runtime - a base package for Flet d...

Operating system:

I only test macOS but I believe this affects all platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant