How to send my user back to my first app screen in Flutter?

I want to send my user back tho my first screen, the home widget passed as parameter to the MaterialApp, but I am very deep into my navigation routes.

class Myapp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyFirstPage(), // <-- I want go on back here
    );
  }
}

There is an easy way of doing it with Flutter?

1 answer

  • answered 2019-06-24 22:30 Daniel Oliveira

    Yes, just do it:

    Navigator.of(context).popUntil(ModalRoute.withName(Navigator.defaultRouteName));
    

    The home widget is for the default route of the app Navigator.defaultRouteName, which is /.