1

I am using GoRouter and the initial page is loading data on initState.

When navigating to another page and going back to the initial page initState isnt called.

How can I detect when the the navigator pops to the intitial page / the initial page is entered to reload the data then?

derChris
  • 726
  • 8
  • 19

1 Answers1

2

I ended up handling that in the GoRoutes builder function

 GoRoute(
        path: HOME,
        builder: _showHomePage,
        routes: ...

and

static Widget _showHomePage(BuildContext context, GoRouterState state) {
    if(GoRouter.of(context).location == HOME){
      fetchNews();
    }
    return HomePage();
  }
derChris
  • 726
  • 8
  • 19
  • A little bit hacky but at leat it works. I cant beleve why this problem is not covered more. I also want to execut initState when back button is called :( Thank you for this solution. Its not nice but at least it should works. – Flutter Supabase Mar 15 '23 at 08:50