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.31k stars 438 forks source link

Gradient Border #3403

Open Flory-1 opened 5 months ago

Flory-1 commented 5 months ago

Support gradient borders for all controles with a border like a container. its insane waht you have to do to create a gradient border.

Here is a "short" example of a gradient border. With this example its not possible to add a border radius thats the next problem.

import flet as ft

class GradientBorder(ft.Container):
    def __init__(self, text: ft.Text, height: float | int = 160, width: float | int = 200, border_width: float | int = 1, border_height: float | int = 1, on_click = None) -> None:
        super().__init__(
            ft.Row(
                [
                    # INFO Left border.
                    ft.Container(
                        width=border_width,
                        height=height,
                        padding=0,
                        gradient=ft.LinearGradient(
                            begin=ft.Alignment(-1, -0.7),
                            end=ft.Alignment(-1, 1),
                            colors=["#000000", "#13aacf"]
                        )
                    ),
                    ft.Container(
                        ft.Column(
                            [
                                # INFO Top border.
                                ft.Container(
                                    height=border_height,
                                    width=width,
                                    padding=0,
                                    bgcolor=ft.colors.with_opacity(0.3, "#000000")
                                ),
                                # INFO Main Content.
                                ft.Container(
                                    text,
                                    width=width,
                                    height=height-border_height-border_height,
                                    padding=0,
                                    bgcolor=ft.colors.with_opacity(0.3, "#000000"),
                                    alignment=ft.alignment.center
                                ),
                                # INFO Bottom border.
                                ft.Container(
                                    height=border_height,
                                    width=width,
                                    padding=0,
                                    bgcolor="#13aacf"
                                )
                            ],
                            spacing=0
                        ),
                        width=width,
                        height=height,
                        padding=0
                    ),
                    # INFO Right border.
                    ft.Container(
                        width=border_width,
                        height=height,
                        padding=0,
                        gradient=ft.LinearGradient(
                            begin=ft.Alignment(-1, -0.7),
                            end=ft.Alignment(-1, 1),
                            colors=["#000000", "#13aacf"]
                        )
                    )
                ],
                spacing=0
            ),
            width=width,
            height=height,
            padding=0,
            on_click=on_click
        )
FeodorFitsner commented 5 months ago

Oh, and there is a package for that: https://pub.dev/packages/gradient_borders 🤩

Flory-1 commented 5 months ago

@FeodorFitsner Thanks for the link but how can i implement this into a python project? I did some research on the flet webpage but i colud not find anything with a clear documentation only the example with spinkit but that documentaion is very strange.