user14824032
user14824032

Reputation:

refresh previous page on Navigator.pop function

Is there any way to refresh the previous page/ stack when Navigator.pop(context) is called? I need to do the API calling of the previous page to refresh the state of the page. The navigator.pop will sometimes be an alert dialog or maybe a back button. Is there a way to do the API calling? ThankYou.

Upvotes: 1

Views: 1195

Answers (2)

Ehsan Askari
Ehsan Askari

Reputation: 891

use the then function after you push another route.

Navigator.of(context).push(
  MaterialPageRoute(
    builder: (context) => MyHomePage(),
  ),
).then(
  (value) {
    if (value) {
      //refresh here
    }
  },
);

and when you return to previous screen, provide the pop function a value that determines whether to perform some action.

Navigator.of(context).pop(true);

Upvotes: 3

Ibrahim Ali
Ibrahim Ali

Reputation: 2511

Previous page

void goToNextPage()async {

 var refresh = await Navigator.push(_context, new MaterialPageRoute(
 builder: (BuildContext context) => new nextPage(context))
 );
if(refresh ) setState((){});

}

NextPage

Navigator.pop(context, true);

Upvotes: 0

Related Questions