I have a column with a Text widget and programmatically added buttons. When I add the buttons, I also give them an on-click event where the container scrolls to the according text container.
However, every button goes to the 'D' row instead
cl = ft.Column(
spacing=10,
height=180,
width=300,
scroll=ft.ScrollMode.ALWAYS
)
for index in range(4):
character = chr(index + ord('A'))
container = ft.Container(
ft.Text("Section " + character),
alignment=ft.alignment.top_left,
bgcolor=ft.colors.BLUE_200,
height=100,
key=character
)
cl.controls.append(container)
buttons = ft.Column([ft.Text("Scroll to:")])
buttonRow = ft.Row()
for index in range(4):
character = chr(index + ord('A'))
button = ft.ElevatedButton(
"Section " + character,
on_click=lambda _: cl.scroll_to(key=character, duration=1000)
)
buttonRow.controls.append(button)
buttons.controls.append(buttonRow)
page.add(ft.Container(cl, border=ft.border.all(1)), buttons)