ListView not scrollable #2855
-
QuestionHey guys, I'm out of my knowledge. I'm building a module in my Flet application. It should be a "list", getting information via API from different services. It has a header row and below that it should look like that. Name Service 1 Service 2 Service 3 Sometimes the list has like 30 rows and is bigger than my window. I can see the first 23 results but then the list is not scrollable. When I do Happy for any hint. Thanks a lot in advance! 🙏 Code samplegui.py from flet import (
AlertDialog,
Container,
colors,
UserControl,
TextField,
ElevatedButton,
icons,
Row,
Column,
Text,
ListView,
ListTile,
TextButton,
padding,
alignment
)
import threading
from modules.onboarding_completeness_check.check_onboarding_completeness import check_onboarding_status
class OnboardingCompletenessCheck(UserControl):
def build(self):
self.title_text = Text("Onboarding Check", weight="bold", size=18)
self.description_text = Text(
"Lorem Ipsum...",
size=16,
)
self.start_date_input = TextField(
label="Start Date",
hint_text="YYYY-MM-DD",
width=300
)
self.check_button = ElevatedButton(
text="Check Status",
on_click=self.on_check_click,
icon=icons.SEARCH,
width=200,
height=50,
)
# Enable auto-scrolling on the ListView
self.status_list_view = ListView(auto_scroll=True)
main_container = Column(
[
Row([], height=10),
self.title_text,
self.description_text,
Row(
[self.start_date_input, self.check_button],
alignment="start",
),
self.status_list_view,
],
expand=True,
)
return main_container
def on_check_click(self, e):
start_date = self.start_date_input.value
if start_date:
self.check_button.text = "Checking..."
self.check_button.icon = icons.HOURGLASS_EMPTY
self.check_button.disabled = True
self.check_button.update()
check_thread = threading.Thread(target=self.check_and_display_status, args=(start_date,))
check_thread.start()
else:
self.page.show_snack_bar("Please enter a start date.")
def check_and_display_status(self, start_date):
try:
people_status = check_onboarding_status(start_date)
self.page.update() # Ensure UI updates occur on the main thread
self.reset_button_state()
# Clear existing items before adding new results
self.status_list_view.controls.clear()
header = Row([
Container(content=Text("No.", weight="bold"), width=50, padding=padding.symmetric(vertical=10, horizontal=5)),
Container(content=Text("Name", weight="bold"), width=250, padding=padding.symmetric(vertical=10, horizontal=5)),
Container(content=Text("Email", weight="bold"), width=300, padding=padding.symmetric(vertical=10, horizontal=5)),
Container(content=Text("Okta", weight="bold"), width=60, padding=padding.symmetric(vertical=10, horizontal=5)),
Container(content=Text("Jira", weight="bold"), width=60, padding=padding.symmetric(vertical=10, horizontal=5)),
Container(content=Text("Google", weight="bold"), width=60, padding=padding.symmetric(vertical=10, horizontal=5)),
])
self.status_list_view.controls.append(header)
total_people = len(people_status)
people_missing_service = 0
for index, person in enumerate(people_status, start=1):
services = person["services"]
missing_service = not all(services.values())
if missing_service:
people_missing_service += 1
row = Row([
Container(content=Text(str(index)), width=50, padding=padding.symmetric(vertical=10, horizontal=5)),
Container(content=Text(person["name"]), width=250, padding=padding.symmetric(vertical=10, horizontal=5)),
Container(content=Text(person["email"]), width=300, padding=padding.symmetric(vertical=10, horizontal=5)),
Container(content=Text("✓" if services["Okta"] else "x", text_align="center", color=colors.GREEN if services["Okta"] else colors.RED), width=60, padding=padding.symmetric(vertical=10, horizontal=5)),
Container(content=Text("✓" if services["Jira"] else "x", text_align="center", color=colors.GREEN if services["Jira"] else colors.RED), width=60, padding=padding.symmetric(vertical=10, horizontal=5)),
Container(content=Text("✓" if services["Google"] else "x", text_align="center", color=colors.GREEN if services["Google"] else colors.RED), width=60, padding=padding.symmetric(vertical=10, horizontal=5)),
])
self.status_list_view.controls.append(row)
self.status_list_view.update()
# Show the summary popup
self.show_summary_popup(total_people, people_missing_service)
except Exception as e:
self.page.update()
self.show_alert_dialog(f"Failed to check onboarding status: {e}")
self.reset_button_state()
def reset_button_state(self):
"""Resets the check button to its initial state."""
self.check_button.text = "Check Status"
self.check_button.icon = icons.SEARCH
self.check_button.disabled = False
self.check_button.update()
def show_alert_dialog(self, message):
dialog = AlertDialog(
title="Error",
content=Text(message),
actions=[
TextButton(text="CLOSE", on_click=lambda _: self.page.close_dialog())
],
)
self.page.show_dialog(dialog)
def show_summary_popup(self, total, missing):
summary_message = f"Total people checked: {total}\nPeople missing at least one service: {missing}"
dialog = AlertDialog(
title=Text("Summary"), # Corrected to use Text control for title
content=Text(summary_message),
actions=[
TextButton(text="CLOSE", on_click=lambda _: self.page.close_dialog())
],
)
self.page.show_dialog(dialog) Error messageNo response ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Try adding expand to ListView:
|
Beta Was this translation helpful? Give feedback.
-
Then could you please provide a complete, runnable repro, so we can investigate? Thanks! |
Beta Was this translation helpful? Give feedback.
OnboardingCompletenessCheck
control itself should be expanded and then all controls in the chain holding ListView: