Canvas + gesture detector does not work in Row parent control #4503
Answered
by
ndonkoHenri
BCheong1990
asked this question in
Q&A
-
Hi, based on the example code, I am trying to canvas + gesture detector to work in a Row parent control but the gestures don't pick up.. Here are the codes. Can someone please shed some light on this matter? import flet as ft class State: state = State() def main(page: ft.Page):
ft.app(main) |
Beta Was this translation helpful? Give feedback.
Answered by
ndonkoHenri
Dec 8, 2024
Replies: 1 comment 1 reply
-
The code works on my end, I am able to draw on the canvas. If it still doesnt work on your end, try constraining your controls, by:
import flet as ft
import flet.canvas as cv
class State:
x: float
y: float
state = State()
def main(page: ft.Page):
page.title = "Flet Brush"
def pan_start(e: ft.DragStartEvent):
state.x = e.local_x
state.y = e.local_y
def pan_update(e: ft.DragUpdateEvent):
cp.shapes.append(
cv.Line(
state.x, state.y, e.local_x, e.local_y, paint=ft.Paint(stroke_width=3)
)
)
cp.update()
state.x = e.local_x
state.y = e.local_y
cp = cv.Canvas(
[
cv.Fill(
ft.Paint(
gradient=ft.PaintLinearGradient(
(0, 0), (600, 600), colors=[ft.Colors.CYAN_50, ft.Colors.GREY]
)
)
),
],
content=ft.GestureDetector(
on_pan_start=pan_start,
on_pan_update=pan_update,
drag_interval=10,
expand=True,
),
expand=True,
)
page.add(
ft.Row(
[
ft.Container(
content=cp,
expand=True,
)
],
expand=True,
)
)
ft.app(main) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ndonkoHenri
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code works on my end, I am able to draw on the canvas.
If it still doesnt work on your end, try constraining your controls, by:
expand=True
for it to fill the available space.