0
import flet


def main(page: flet.Page):
    page.add(
        flet.IconButton(
            icon="delete",
            style=flet.ButtonStyle(
                color={
                    flet.MaterialState.HOVERED: flet.colors.WHITE,
                    flet.MaterialState.DEFAULT: flet.colors.BLACK,
                },
                animation_duration=500,
            ),
        )
    )


flet.app(target=main)

This code generates a window with IconButton. There is two parameters: color (in hovered and default state) and animation_duration in it's ButtonStyle. Although animation_duration is used it's not working as needed.

import flet


def main(page: flet.Page):
    page.add(
        flet.TextButton(
            "delete",
            style=flet.ButtonStyle(
                color={
                    flet.MaterialState.HOVERED: flet.colors.WHITE,
                    flet.MaterialState.DEFAULT: flet.colors.BLACK,
                },
                animation_duration=500,
            ),
        )
    )


flet.app(target=main)

This one is what I am aiming for. The same code, but instead IconButton used TextButton with text not an icon. The issue is smooth animation of changing color for text works fine, but for icon it don't work at all.

1 Answers1

0

Although, this question must be a bag, I found some kind of solution:

import flet as ft


def main(page: ft.Page):
    def animate_opacity(e):
        e.control.opacity = 0 if e.control.opacity == 1 else 1
        e.control.update()
    c = ft.TextButton(content=ft.Icon("delete", color=ft.colors.BLACK),
                      opacity=0,
                      animate_opacity=300,
                      on_hover=animate_opacity)

    page.add(c)


ft.app(target=main)

This code makes a little button in left-top corner. And than it's hovered it's smoothly appears and if not it's smoothly disappears