Skip to content

PaintLinearGradient

PaintLinearGradient #

Bases: PaintGradient

More information on Linear gradient https://api.flutter.dev/flutter/dart-ui/Gradient/Gradient.linear.html

begin #

begin: OffsetValue | None

The offset at which stop 0.0 of the gradient is placed.

color_stops #

color_stops: list[Number] | None = None

A list of values from 0.0 to 1.0 that denote fractions along the gradient.

Note

If non-none, this list must have the same length as colors. If the first value is not 0.0, then a stop with position 0.0 and a color equal to the first color in colors is implied. If the last value is not 1.0, then a stop with position 1.0 and a color equal to the last color in colors is implied.

colors #

colors: list[str]

The https://flet.dev/docs/reference/colors the gradient should obtain at each of the stops. This list must contain at least two colors.

Note

If color_stops is not None, this list must have the same length as color_stops.

end #

end: OffsetValue | None

The offset at which stop 1.0 of the gradient is placed.

tile_mode #

tile_mode: GradientTileMode = CLAMP

How this gradient should tile the plane beyond in the region before begin and after end.

copy_with #

copy_with(
    *,
    begin: OffsetValue | None = None,
    end: OffsetValue | None = None,
    colors: list[str] | None = None,
    color_stops: list[Number] | None = None,
    tile_mode: GradientTileMode | None = None,
) -> PaintLinearGradient

Returns a copy of this object with the specified properties overridden.

Examples#

Canvas paint#

import flet as ft
import flet.canvas as cv


def main(page: ft.Page):
    page.add(
        cv.Canvas(
            width=float("inf"),
            expand=True,
            shapes=[
                cv.Rect(
                    x=10,
                    y=10,
                    width=100,
                    height=100,
                    border_radius=5,
                    paint=ft.Paint(
                        style=ft.PaintingStyle.FILL,
                        gradient=ft.PaintLinearGradient(
                            begin=(0, 10),
                            end=(100, 50),
                            colors=[ft.Colors.BLUE, ft.Colors.YELLOW],
                        ),
                    ),
                ),
            ],
        )
    )


ft.run(main)

canvas-paint