How could I make the name()
function run whenever the Page1
page appeared?
In the code below before going to Page2
I execute t
One way of doing this is to use the .whenComplete()
method on the Navigator widget.
Suppose you are going to the second page from the first page. Here you have to pass the functionThatSetsTheState
as a pointer to the navigation part of your code.
The function looks like this and should be in a Stateful Widget.
void functionThatSetsTheState(){
setState(() {});
}
Your navigation code for OnPressed
, OnTap
, OnLongPress
, etc.
Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) => SecondPage())).whenComplete(() => {functionThatSetsTheState()});