I have a page that goes after the main page which has its own ChangeNotifierProvider
. The key given in the main
method of the first page is a static String stored in the ChangeNotifierProvider
class that I use in the second page.
When I update this String
key before Navigator.pop() into the first page, coming back to the second page still has the same old values.
I heard changing the key lets you refresh the Provider stored values, so how do I do it? Or else how can I make sure everything is reset once I click a certain button to go back?
CodePudding user response:
In order to update data from Provider you need to call notifylisteners()
in method of your Provider like this:
updateString(String newData){
oldData = newData;
notifyListeners();
}
CodePudding user response:
I had thought that there was such a function like this in Provider but no, would've been useful.
For now my solution was to create constructor methods that set everything back, so I can call them before I navigate.