I suggest using name routes, it's more easy even if you're app gets bigger with more pages. I prefer to let widgets outside main.dart and inside dart just use logic and routes, and after Create those 3 pages that you need A,B,C and set in you're main dart code that you're first page(home page) has to be page A.
Go on you're pages and just under Statefull{ or Stateless { type the route name:
static const routeName = '/pageA';
static const routeName = '/pageB';
static const routeName = '/pageC';
Define in your main.dart the routes:
home: WidgetFromPageA(),
routes: {
WidgetFromPageB.routeName: (ctx) => WidgetFromPageB(),
WidgetFromPageC.routeName: (ctx) => WidgetFromPageC(),
},
From any page you can call this action:
Navigator.of(context).pushNamed(WidgetFromPageA.routeName);
Navigator.of(context).pushNamed(WidgetFromPageB.routeName);
Navigator.of(context).pushNamed(WidgetFromPageC.routeName);
In this way you can go to page B and on the new page in the app bar you got the return button.
For example, when you are in the second page, use the pushReplacement() method and open the third page, when you hit the back button you will go to the first page and skip the second page.
To make it more clear you can navigate to the forth page like this:
[ 1 --push()--> 2 --pushReplacement()--> 3 --pushReplacement()--> 4] and when you hit the back button you will get to the first page.