EDIT: As pointed out by @Augustin, the following way works in ALL cases when the second screen is popped and NOT JUST ONLY WHEN THE BACK BUTTON IS PRESSED.
In short - You can use .then() on the Navigator.push()
Why? and How?
Home Screen - from the screen you're navigating
Second Screen - to the screen you're navigating
The Navigator on the home screen returns a future that gets 'completed' when the page is popped i.e. when the Navigator.pop() runs on the second screen
So, the .then() method on the Navigator.push() (home screen) will run when your page (second screen) is popped.
Something like this -
HOME SCREEN
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (ctx) => SecondPage()
)).then(
(context) {
isAppleRed();
}
);
},
tooltip: 'Increment',
child: Icon(Icons.add),
),
isAppleRed() - Just to keep things clear :p
bool isAppleRed() {
print('Yes!');
return true;
}
Once the back button on the SECOND SCREEN is pressed, the code inside the .then block will run.
Hope that is any sort of help for you :)