0

In a Flutter app,

  1. I'm getting a list of objects on page A
  2. I go to page B to edit an object
  3. I return to page A but my edits from the previous step are not visible (data is not reloaded)

I'm using Go Router .go method to navigate between routes. When I return to page A, I need to reload it by calling initState but since it's already in the element tree, initState won't be called. What's the best way to force a route to refresh on return. I assume it's a common case for apps.

I'm using ShellRoutes with Go Router and this particular scenario happened within a ShellRoute. I run the following sequence:

  1. context.go('objects_list')
  2. context.go('object_details)
  3. Make edits to the object
  4. context.go('objects_list')

When I return to 'objects_list' route from 'objects_details', it won't refresh and still shows the old data. I need a way to force it to refresh. I have used .replace instead of .go method but since it replaces at the top navigator, it won't work.

  • Maybe you can use [RouteAware](https://api.flutter.dev/flutter/widgets/RouteAware-class.html) for that? – quoci Jul 07 '23 at 06:15
  • If your page needs to rebuild because data has changed, but it isn't, it means you're missing a dependency in this reactive framework. With Riverpod, you'd need to add a ref.watch on some provider of the data. If not Riverpod, find the equivalent. – Randal Schwartz Jul 07 '23 at 15:08

0 Answers0