1

I want to have page A reload, re-run the Http requests, once I pop back to it from another page that lets you edit the data page A displays. The other page is triggered by a long press in a ListView generated by a function within page A. IE: Page A:

_PageAState

  • Reload function I need to call

Scaffold

  • List item

  • Text

  • ETC...
  • Expanded
    • ListView
      • Gesture Detector that navigates
  • ETC

How can I trigger a function of any sort or make the page reload when I pop back to it?

I've tried passing data from the pop and using an if statement but the nested structure messes it up.

snibo
  • 11
  • 1
  • 4

1 Answers1

1

of course, there's a way to do that! As you realized, the first route needs to get notified when the pushed Route gets popped.

Thankfully, there's a tutorial in the Flutter documentation that handles returning data from Routes. In your case, no data gets returned but you can still use the same principle to wait for the route to be popped: Simply await the Navigator.push call! This will return once the other route gets popped.

await Navigator.push(
  context,
  MaterialPageRoute(builder: (context) => OtherPage()),
);
// TODO: Now, refetch the data.
Marcel
  • 8,831
  • 4
  • 39
  • 50
  • The issue with this solution is that the Navigation is in a different file and class from the data function. I have a ListBuilder and the item's for the ListBuilder in a separate file and class from Page A. I can't seem to access any of the methods declared in _PageAState I'm not sure how I could go about doing that. – snibo Jun 04 '19 at 16:50
  • Ahh, I see. Well, as far as I know forcing a widget on a different page to update itself doesn't align with how Flutter's rendering works, so my educated guess is this isn't possible. – Marcel Jun 05 '19 at 07:55