-
Notifications
You must be signed in to change notification settings - Fork 607
Closed
Labels
Description
Description
I’m using the Tabs control to create a PDF reader where each tab represents a page of the PDF. I’m asynchronously creating the tabs for each page with the intention of allowing users to switch pages while the remaining tabs are still being created. The problem is that every time the control updates, it returns to the first page. In other words, until the tab creation process completes, I cannot switch pages.
Code example to reproduce the issue:
def main(page: ft.Page):
page.theme_mode = 'dark'
t = ft.Tabs(selected_index=0,scrollable=True)
async def extract_pdf_pages(file):
for page in file.pages:
yield page
async def update_t():
lector = pypdf.PdfReader("Por ti - Laimie Scott.pdf")
async for i in extract_pdf_pages(lector):
text = i.extract_text()
image_list =i.images
if image_list:
xref = image_list[0]
data = xref.data
image_base64 = base64.b64encode(data).decode('utf-8')
t.tabs.append(
ft.Tab(
content=ft.Column(
expand=True,
controls=[
ft.Image(src_base64=image_base64, fit=ft.ImageFit.COVER),
]
)
)
)
if not "Página 181" == text:
t.tabs.append(
ft.Tab(
content=ft.Markdown(
#selectable=True,
value=text
)
)
)
else:
t.tabs.append(
ft.Tab(
content=ft.Markdown(
#selectable=True,
value=text
)
)
)
await t.update_async()
await asyncio.sleep(0.1)
page.add(t)
page.run_task(update_t)
page.update()
if __name__ == "__main__":
ft.app(main, assets_dir="assets")
Additional information you deem important (e.g. issue happens only occasionally):
Flet version (pip show flet):
0.21.1
Give your requirements.txt file (don't pip freeze, instead give direct packages):
flet
bs4
werkzeug
robobrowser
request
pypdf
Operating system:
Windows