Navigate to a new screen and back : Return to the first route using Navigator.pop() #

How do you close the second route and return to the first? By using the Navigator.pop() method. The pop() method removes the current Route from the stack of routes managed by the Navigator.

To implement a return to the original route, update the onPressed() callback in the SecondRoute widget:

// Within the SecondRoute widget

onPressed: () {

 Navigator.pop(context);

}

Leave a comment

Your email address will not be published. Required fields are marked *