Skip to content

Routing / Navigation broken since flet 0.28.2 #5302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
NiTRoeSE opened this issue May 13, 2025 · 8 comments
Closed
1 task done

Routing / Navigation broken since flet 0.28.2 #5302

NiTRoeSE opened this issue May 13, 2025 · 8 comments
Assignees
Labels
bug: regression A feature that worked correctly doesn't anymore bug Something isn't working
Milestone

Comments

@NiTRoeSE
Copy link

NiTRoeSE commented May 13, 2025

Duplicate Check

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/[email protected]/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

Captures Image

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/[email protected]/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

@FeodorFitsner
Copy link
Contributor

Sorry, but how would someone "navigate back through the buttons"? It works fine with the mouse:

Screen.Recording.2025-05-13.at.2.12.35.PM.mov

@C69Xg3sg9PAvYK
Copy link

I have the same issue.

@FeodorFitsner
Copy link
Contributor

Looking into that.

@FeodorFitsner FeodorFitsner self-assigned this May 13, 2025
@NiTRoeSE
Copy link
Author

Sorry, but how would someone "navigate back through the buttons"? It works fine with the mouse:
Screen.Recording.2025-05-13.at.2.12.35.PM.mov

Yes i mean using the mouse but clicking with it on the buttons " Visit Store" and "Go Home".
If you click "Visit Store" and want to go back with the "Go Home" Button instead of using the Arrow button in appbar to go back then the error is shown.

Or in other words if you use on_click=lambda _: page.go("/") on a button to navigate back the error is thrown.

@FeodorFitsner
Copy link
Contributor

Got it. Can reproduce. Looking into that.

FeodorFitsner added a commit that referenced this issue May 14, 2025
@FeodorFitsner FeodorFitsner added bug Something isn't working bug: regression A feature that worked correctly doesn't anymore labels May 14, 2025
@FeodorFitsner FeodorFitsner added this to the Flet v0.28.3 milestone May 14, 2025
@Ayyouayy
Copy link

This is used

 def view_pop(view):
        page.views.pop()
        if page.views: 
            top_view = page.views[-1]
            page.go(top_view.route)

@FeodorFitsner
Copy link
Contributor

We've made a fix coming in 0.28.3, so won't need to change the logic.

@puppylionmonkey
Copy link

我是會觸發pop之後無限遞迴下去,直接把所有page.view刪光光

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: regression A feature that worked correctly doesn't anymore bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants