Learn/Navigation/Passing Data Between Screens

Passing Data Between Screens

Send and receive data when navigating

6 min~5 min read+35 FX

You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.

Table of Contents

  1. 1. Method 1: Constructor Arguments
  2. 2. Method 2: Route Arguments
  3. 3. Returning Data from a Screen
  4. 4. Data Passing Strategy
  5. 5. This Lesson In Simple Words
  6. 6. Your level focus
  7. 7. One practical habit
  8. 8. Deep Understanding Guide
  9. 9. Why this lesson matters
  10. 10. Study flow for better retention
  11. 11. Quick Glossary

Having trouble? AI is here to help

Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.

Use the AI button at the bottom of the screen

Passing Data Between Screens

There are several ways to pass data between screens in Flutter.

Method 1: Constructor Arguments

The simplest way to pass data is through the constructor of the destination screen widget. You define the required fields in the screen class, then provide the values when you create it inside MaterialPageRoute.

dart
1// Pass data via constructor
2class ProductScreen extends StatelessWidget {
3 final String productId;
4 final String productName;
5
6 const ProductScreen({
7 required this.productId,
8 required this.productName,
9 });
10
11 @override
12 Widget build(BuildContext context) {
13 return Scaffold(
14 appBar: AppBar(title: Text(productName)),
15 body: Text('Product ID: $productId'),
16 );
17 }
18}
19
20// Navigate with data
21Navigator.push(
22 context,
23 MaterialPageRoute(
24 builder: (context) => ProductScreen(
25 productId: '123',
26 productName: 'Flutter Course',
27 ),
28 ),
29);

Method 2: Route Arguments

When using named routes, you cannot pass constructor arguments directly. Instead, use the arguments parameter of pushNamed to send a Map or any object, and then extract it in the destination screen using ModalRoute.

dart
1// Navigate with arguments
2Navigator.pushNamed(
3 context,
4 '/product',
5 arguments: {'id': '123', 'name': 'Flutter Course'},
6);
7
8// Receive arguments in the screen
9class ProductScreen extends StatelessWidget {
10 @override
11 Widget build(BuildContext context) {
12 // Extract arguments
13 final args = ModalRoute.of(context)!.settings.arguments
14 as Map<String, dynamic>;
15
16 return Scaffold(
17 appBar: AppBar(title: Text(args['name'])),
18 body: Text('ID: ${args['id']}'),
19 );
20 }
21}

Returning Data from a Screen

Sometimes you need the destination screen to send a result back. Navigator.pop accepts an optional second argument that becomes the return value of the original push call. The calling screen must await the result.

dart
1// Screen that returns data
2class SelectColorScreen extends StatelessWidget {
3 @override
4 Widget build(BuildContext context) {
5 return Scaffold(
6 body: Column(
7 children: [
8 ListTile(
9 title: Text('Red'),
10 onTap: () => Navigator.pop(context, 'red'),
11 ),
12 ListTile(
13 title: Text('Blue'),
14 onTap: () => Navigator.pop(context, 'blue'),
15 ),
16 ],
17 ),
18 );
19 }
20}
21
22// Navigate and await result
23void selectColor() async {
24 final selectedColor = await Navigator.push<String>(
25 context,
26 MaterialPageRoute(builder: (context) => SelectColorScreen()),
27 );
28
29 if (selectedColor != null) {
30 print('User selected: $selectedColor');
31 }
32}

Data Passing Strategy

Pick data passing style based on complexity:

  • constructor args for simple strongly typed data
  • route arguments for centralized named-route flows
  • returned pop result for one-time user choices

Prefer typed model objects over loose maps whenever possible, because typed contracts catch mistakes earlier.

Data Flow Checklist

  • Required fields are validated before navigation.
  • Receiving screen handles missing or malformed arguments safely.
  • Returned values are null-checked before applying state changes.
  • Sensitive data is not passed in plain route maps unnecessarily.

This Lesson In Simple Words

Send and receive data when navigating. This lesson adds one more building block for creating stable and user-friendly Flutter apps.

Your level focus

Connect each concept to real app features you can build.

One practical habit

After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.

Deep Understanding Guide

Why this lesson matters

Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.

Study flow for better retention

  1. Map the lesson to one screen, one user action, and one expected output.
  2. Use a simple cycle: understand, implement, test, and explain.
  3. If you can choose between two approaches and explain why, you are improving.

Common Mistakes To Avoid

  • Moving forward without checking whether the current concept is truly clear.
  • Copying code exactly without experimenting with small changes.
  • Skipping edge cases and only testing happy-path behavior.
  • Assuming one pattern works for every scenario without trade-off analysis.

Practice Sprint (15-25 Minutes)

  • Before running sample code, predict output and behavior in one sentence.
  • Build one tiny example from memory after finishing this lesson.
  • Write one paragraph about where this concept fits in a real app.
  • Create one failure scenario and verify your app handles it safely.
  • Complete the required exercises without using hints on the first attempt.
  • Answer this question out loud before checking quiz options: "How can you pass data back when navigating back?".

Quick Glossary

  • widget: A reusable UI building block in Flutter.
  • navigator: A stack manager that controls screen transitions.
  • route: A screen entry managed by the Navigator.
  • const: A compile-time constant that can reduce rebuild work.

Code Comprehension Drill

  • State the purpose of the code block in one line before reading details.
  • Mark inputs, state changes, and final output.
  • Change one small value and predict what should happen before running.
  • Run again and compare your prediction with actual behavior.

Lesson Completion Checklist

  • I can explain "Passing Data Between Screens" in simple words without reading notes.
  • I can describe one real app situation where this concept is required.
  • I know at least one mistake to avoid: Moving forward without checking whether the current concept is truly clear.
  • I can modify one code sample and correctly predict the behavior change.
  • I can finish required exercises with understanding, not trial-and-error guesses.

Frequently Asked Questions

How can you pass data back when navigating back?

Navigator.pop() accepts an optional second argument that is returned to the previous screen.

How do you receive data returned from Navigator.push()?

Navigator.push() returns a Future that resolves with the value passed to pop().

How do you extract route arguments in the receiving screen?

ModalRoute.of(context)!.settings.arguments retrieves the arguments passed via pushNamed.

Which method is best for passing a simple object to a new screen?

Passing data via constructor is the simplest and most direct way to send data to a new screen.

Suggest Improvement

Something seems incorrect, unclear, or missing? Let us know.

About The Author

FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.

Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.

Sign in to continue with exercises and quiz for this lesson.

Sign In to Continue