Closed
Description
Duplicate Check
- I have searched the opened issues and there are no duplicates
Describe the bug
Working navigation like inplemented like in this example:
https://flet.dev/docs/getting-started/navigation-and-routing/#building-views-on-route-change
seems broken or something changed and is undocumented ?
If you use the example and navigate back through the buttons (not the back arrows) it throws following error:
Future exception was never retrieved
future: <Future finished exception=IndexError('list index out of range')>
Traceback (most recent call last):
File "/opt/homebrew/Cellar/python@3.13/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/concurrent/futures/thread.py", line 59, in run
result = self.fn(*self.args, **self.kwargs)
File "/Users/nitro/flet_build/scriptrunner_flet/venv/lib/python3.13/site-packages/flet/core/page.py", line 906, in wrapper
handler(*args)
~~~~~~~^^^^^^^
File "/Users/nitro/flet_build/scriptrunner_flet/test.py", line 31, in view_pop
top_view = page.views[-1]
~~~~~~~~~~^^^^
IndexError: list index out of range
So something goes wrong with page.on_view_pop = view_pop
Same app or navigation build like in example works fine in flet < 0.28.2.
Code sample
Code
import flet as ft
def main(page: ft.Page):
page.title = "Routes Example"
def route_change(route):
page.views.clear()
page.views.append(
ft.View(
"/",
[
ft.AppBar(title=ft.Text("Flet app"), bgcolor=ft.Colors.SURFACE_CONTAINER_HIGHEST),
ft.ElevatedButton("Visit Store", on_click=lambda _: page.go("/store")),
],
)
)
if page.route == "/store":
page.views.append(
ft.View(
"/store",
[
ft.AppBar(title=ft.Text("Store"), bgcolor=ft.Colors.SURFACE_CONTAINER_HIGHEST),
ft.ElevatedButton("Go Home", on_click=lambda _: page.go("/")),
],
)
)
page.update()
def view_pop(view):
page.views.pop()
top_view = page.views[-1]
page.go(top_view.route)
page.on_route_change = route_change
page.on_view_pop = view_pop
page.go(page.route)
ft.app(main)
To reproduce
Use example and run with flet 0.28.2
Expected behavior
That it works like in previous versions.
Screenshots / Videos
Operating System
macOS
Operating system details
15.4.1
Flet version
0.28.2
Regression
Yes, it used to work in a previous Flet version (please specify the version in additional details)
Suggestions
i dont know...
Logs
Logs
(venv) nitro@Mac ~/flet_build/scriptrunner_flet main ± python test.py
Future exception was never retrieved
future: <Future finished exception=IndexError('list index out of range')>
Traceback (most recent call last):
File "/opt/homebrew/Cellar/python@3.13/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/concurrent/futures/thread.py", line 59, in run
result = self.fn(*self.args, **self.kwargs)
File "/Users/nitro/flet_build/scriptrunner_flet/venv/lib/python3.13/site-packages/flet/core/page.py", line 906, in wrapper
handler(*args)
~~~~~~~^^^^^^^
File "/Users/nitro/flet_build/scriptrunner_flet/test.py", line 31, in view_pop
top_view = page.views[-1]
~~~~~~~~~~^^^^
IndexError: list index out of range
Additional details
No response