Mayank
Mayank

Reputation: 1983

Flutter - How to Update Home Route After Returning from MaterialPageRoute

This is my App's flow:

App's Flow

How do I update the Home Page when I press back and return to it from the MaterialPageRoute? I attempted to use the setState method in the dispose() method of MaterialPageRoute, but it gave me an error.

Upvotes: 0

Views: 472

Answers (2)

Mayank
Mayank

Reputation: 1983

Actually, the Home Page is automatically updated, however I made a mistake by updating the variable within the dispose() method, which is invoked after the Home Page has been updated.

Upvotes: 0

esentis
esentis

Reputation: 4666

You can use Navigator.push(context,MaterialPageRoute(builder: (context) => TheSecondPage())).then((value) { setState(() {}); thus when you pop from TheSecondPage() you will immediatelly call the setState refreshing the page.

Upvotes: 1

Related Questions