Rates TodayNIFTY25,819.3+2.34%SENSEX83,938.3+2.32%Gold 24K ₹11,235.62/g down271.8Silver ₹128.69/g down5.77
InsightforGeeks
FlutterPart of the Flutter learning hub

Flutter Navigation: Navigator, Named Routes and Passing Data

insightforgeeks-editorial
25 Nov 2026
3 min read
Share:

A Flutter app is a stack of screens. Moving between them is done with the Navigator: you push a screen on top to go forward and pop it to go back. This guide covers the basic push and pop, how to send data to the next screen and get a result back, and when to use named routes.

Go to another screen and come back

// Go forward
Navigator.push(
  context,
  MaterialPageRoute(builder: (context) => const DetailsScreen()),
);

// Go back (for example from a button on DetailsScreen)
Navigator.pop(context);

The AppBar on the new screen shows a back arrow automatically, and the Android back button does the same as pop.

Pass data to the next screen

The simplest way is a constructor argument. It is typed, so the compiler catches mistakes.

class DetailsScreen extends StatelessWidget {
  final String title;
  const DetailsScreen({super.key, required this.title});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(title)),
      body: Center(child: Text('Details for $title')),
    );
  }
}

// Using it
Navigator.push(
  context,
  MaterialPageRoute(builder: (_) => DetailsScreen(title: 'Tea')),
);

Get a result back

push returns a Future that completes when the screen is popped. Give pop a value to send back.

// On the first screen
final choice = await Navigator.push<String>(
  context,
  MaterialPageRoute(builder: (_) => const PickerScreen()),
);
if (!context.mounted) return; // the screen may have gone while waiting
if (choice != null) {
  ScaffoldMessenger.of(context)
      .showSnackBar(SnackBar(content: Text('You picked $choice')));
}

// On PickerScreen, when the user chooses
Navigator.pop(context, 'Coffee');

The context.mounted check matters: using a BuildContext after an await without it can crash if the user already left the screen.

Named routes

Named routes give each screen a string name, declared once in MaterialApp.

MaterialApp(
  initialRoute: '/',
  routes: {
    '/': (context) => const HomeScreen(),
    '/settings': (context) => const SettingsScreen(),
  },
);

// Go there
Navigator.pushNamed(context, '/settings');

They are tidy for a handful of fixed screens. To pass data to a named route you use arguments and read them with ModalRoute.of(context)!.settings.arguments, which is untyped. For routes that need data, plain push with a constructor is safer.

Replace instead of stack

  • Navigator.pushReplacement swaps the current screen, useful after a login so the user cannot go back to it.
  • Navigator.pushAndRemoveUntil clears the stack down to a point, for example to start fresh at the home screen after sign-out.

Which should you use?

  • A few screens: Navigator.push with constructor arguments.
  • Web links, deep links or many screens: consider the go_router package, which supports URLs, redirects and typed parameters.

Navigation and state go together: decide where shared data lives before you wire screens up. Our state management guide and the Flutter learning hub are the next reads.

Tags:#flutter#dart#navigation#routes
Found this helpful? Share it with friends & colleagues
Share:
insightforgeeks-editorial Verified Editorial Staff

Covering financial markets, commodity rates, and practical technology insights for India. Researched and fact-checked in accordance with our Editorial Policy.

Published on 25 November 2026General Information · Disclaimer

Recommended based on your reading interest

More in Flutter