You can use WillPopScope for that. It's a class that notifies you when the
enclosing ModalRoute (internally used with the Navigator) is about to be
popped. It even leaves you a choice to whether or not you want the pop to
happen.
Just wrap the second screen's Scaffold in a WillPopScope.
return WillPopScope(
onWillPop: () async {
// You can do some work here.
// Returning true allows the pop to happen, returning false prevents it.
return true;
},
child: ... // Your Scaffold goes here.
);