2

In Flutter let a route /a is displayed. Then I press Edit button what pushes route /b. The route /b changes data in the SQLite DB and then I call Navigator.pop so returning to the route /a.

Now route /a displays the old (unedited) version of the data.

I need in some way route /b to send to route /a an "update" signal.

How to do it? The best solution I came to is to pass the widget /a (or better its state) in pushNamed arguments parameter. This is awkward however, particularly because this requires onUpdate handler to be passed down to the subwidget of /a that actually reads data from DB possibly through a chain of several widgets. Is the way that I described here the idiomatic Flutter way, or is there a better solution?

porton
  • 5,214
  • 11
  • 47
  • 95

2 Answers2

3

Wait for the result from another route.

final result = await Navigator.push(...);

Return the result.

Navigator.pop(context, 'Hello!');

See Return data from a screen for details.

user18309290
  • 5,777
  • 2
  • 4
  • 22
0

You need to use any state management. For example in getx state management you can make your data variable observable and any where you are using that variable you can wrap it with Obx. So whenever the variable is changing you can get the same changes everywhere.

Why_So_Ezz
  • 160
  • 1
  • 7