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.5k stars 449 forks source link

`Segment.tooltip` must be of type string #4324

Closed lasifea closed 1 week ago

lasifea commented 2 weeks ago

Duplicate Check

Describe the bug

I found that when I set the tooltip in the Segment component, the text displayed incorrectly, and the same issue also exists in other components, such as the BarChartRod component. In version 0.23.2, this issue will not occur. (From machine translation, please understand if the expression is inaccurate.)

Code sample

Code ```python import flet as ft def main(page: ft.Page): page.horizontal_alignment = ft.CrossAxisAlignment.CENTER page.vertical_alignment = ft.MainAxisAlignment.CENTER page.window.width = 500 page.window.height = 300 segments = [ft.Segment('0', icon=ft.Icon(ft.icons.LOOKS_ONE), label=ft.Text('Dog', size=16), tooltip='a dog'), ft.Segment('1', icon=ft.Icon(ft.icons.LOOKS_TWO), label=ft.Text('Cat', size=16), tooltip='一只猫'), ft.Segment('2', icon=ft.Icon(ft.icons.LOOKS_3), label=ft.Text('Bird', size=16), tooltip=ft.Tooltip('一只鸟', padding=20, border_radius=10))] segment_btn = ft.SegmentedButton(segments=segments, selected={'0'}, selected_icon=ft.Icon(ft.icons.CHECK)) page.add(segment_btn) if __name__ == '__main__': ft.app(main) ```

To reproduce

After running, please notice the tooltip of the button.

Expected behavior

No response

Screenshots / Videos

Captures [Upload media here] ![image](https://github.com/user-attachments/assets/c2e7440e-33eb-44db-9d0f-99a75d18a86f)

Operating System

Windows

Operating system details

Windows 11

Flet version

0.24.1

Regression

No, it isn't

Suggestions

No response

Logs

Logs ```console [Paste your logs here] ```

Additional details

There may still be some components that have the same issue, but I haven't encountered them yet.

ndonkoHenri commented 2 weeks ago

Seems like this property must be of type of string.

ndonkoHenri commented 2 weeks ago

Two ways to display a tooltip in the Segment:

Example:

import flet as ft

def main(page: ft.Page):
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
    page.vertical_alignment = ft.MainAxisAlignment.CENTER

    page.add(
        ft.SegmentedButton(
            selected={"0"},
            selected_icon=ft.Icon(ft.icons.CHECK),
            segments=[
                ft.Segment(
                    value="0",
                    icon=ft.Icon(ft.icons.LOOKS_ONE),
                    label=ft.Text("I am Text", size=16),
                    tooltip="tooltip from text",
                ),
                ft.Segment(
                    value="2",
                    icon=ft.Icon(ft.icons.LOOKS_3),
                    label=ft.Text(
                        "I am Class",
                        size=16,
                        tooltip=ft.Tooltip(
                            message="tooltip from class",
                            padding=3,
                            border_radius=10,
                            gradient=ft.LinearGradient(
                                colors=[ft.colors.RED, ft.colors.BLUE]
                            ),
                        ),
                    ),
                ),
            ],
        )
    )

ft.app(main)

Disadvantage with the second option is that, the tooltip will only be visible when hovering on the label. So, hovering on the icon won't show the tooltip.

lasifea commented 2 weeks ago

OK, I'm watting for the next version of Flet. Thanks!