Why does scroll & expand behaves differently in a UserControl #2115
-
QuestionI would like to create a UserControl with expand and scrolling, but I could not manage yet. Code sample# 1st example
# flet test with scrolling & expand
import flet as ft
def main(page: ft.Page):
cl = ft.Column(
spacing=10,
height=200,
width=400,
scroll=ft.ScrollMode.ALWAYS,
)
for i in range(0, 50):
cl.controls.append(ft.Text(f"Text line {i}", key=str(i)))
def scroll_to_key(e):
cl.scroll_to(key="20", duration=1000)
myContainer = ft.Container(
ft.Column(
controls=[
ft.Text("Title", size=20),
ft.Container(cl, border=ft.border.all(1), expand = True),
ft.ElevatedButton("Scroll to key '20'", on_click=scroll_to_key),
]
),
expand=True,
)
page.add(myContainer)
ft.app(main)
# 2nd example
# flet test with scrolling, expand & UserControl
import flet as ft
class FletApp(ft.UserControl):
def build(self):
self.cl = ft.Column(
spacing=10,
height=200,
width=400,
scroll=ft.ScrollMode.ALWAYS,
)
for i in range(0, 50):
self.cl.controls.append(ft.Text(f"Text line {i}", key=str(i)))
return ft.Container(
ft.Column(
controls=[
ft.Text("Title", size=20),
ft.Container(self.cl, border=ft.border.all(1), expand = True),
ft.ElevatedButton("Scroll to key '20'", on_click=self.scroll_to_key),
]
),
expand=True,
)
def scroll_to_key(self, e):
self.cl.scroll_to(key="20", duration=1000)
def main(page: ft.Page):
fletApp = FletApp()
page.add(fletApp)
ft.app(main) Error messageNo response ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Answered by
ndonkoHenri
Dec 2, 2023
Replies: 1 comment
-
You need to expand the Usercontrol too. The below example works as expected: import flet as ft
class FletApp(ft.UserControl):
def __init__(self, expand=None):
super().__init__(expand=expand)
def build(self):
self.cl = ft.Column(
spacing=10,
height=200,
width=400,
scroll=ft.ScrollMode.ALWAYS,
)
for i in range(0, 50):
self.cl.controls.append(ft.Text(f"Text line {i}", key=str(i)))
return ft.Container(
ft.Column(
controls=[
ft.Text("Title", size=20),
ft.Container(self.cl, border=ft.border.all(1), expand=True),
ft.ElevatedButton("Scroll to key '20'", on_click=self.scroll_to_key),
]
),
expand=True,
)
def scroll_to_key(self, e):
self.cl.scroll_to(key="20", duration=1000)
def main(page: ft.Page):
fletApp = FletApp(expand=True)
page.add(fletApp)
ft.app(main) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
hplehn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to expand the Usercontrol too. The below example works as expected: