3

I am an android developer and now learning about flutter development. In flutter navigator is using to move one page to another like intents in android. While I am using navigate, the back is goes to the initial page.

Am using the below code for navigation.

Navigator.of(context).pushReplacement(
        MaterialPageRoute(builder: (c) => widget.user ? Dashboard() : Login()),
      );
kapil tk
  • 186
  • 10

3 Answers3

3

You can use Navigator.push(context) for navigate from one page another using button, like the following:

onPressed: () {
  Navigator.push(
    context,
    MaterialPageRoute(
      builder: (context) => const ScreenDashboard(),
    ),
  );
},
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
1

Navigation in Flutter is implemented as stack, so when you are using function Navigator.of(context).pushReplacement navigator replaces your current page with new one. If you want to save previous page also, use Navigator.of(context).push instead

0

Flutter docs suggests using go_router package for Navigation.

Flutter applications with advanced navigation and routing requirements (such as a web app that uses direct links to each screen, or an app with multiple Navigator widgets) should use a routing package such as go_router that can parse the route path and configure the Navigator whenever the app receives a new deep link.


Reference questions regarding go_router:

krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88