Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

how to implement onbackpressed in flutter

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.
);
 
PREVIOUS NEXT
Tagged: #implement #onbackpressed #flutter
ADD COMMENT
Topic
Name
4+4 =