Learn/Navigation/Returning Data From Screens

Returning Data From Screens

Pass data back to the previous screen after navigation

4 min~4 min read+30 FX

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

Table of Contents

  1. 1. Result-Driven Flows
  2. 2. This Lesson In Simple Words
  3. 3. Your level focus
  4. 4. One practical habit
  5. 5. Deep Understanding Guide
  6. 6. Why this lesson matters
  7. 7. Study flow for better retention

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

Returning Data From Screens

Sometimes a screen needs to send data back to whoever opened it. For example, a color picker screen returning the selected color, or a form screen returning the submitted data.

dart
1// ── Returning data with Navigator.pop() ──
2
3// On the receiving screen (calls pop with result)
4class ColorPickerScreen extends StatelessWidget {
5 @override
6 Widget build(BuildContext context) {
7 return Scaffold(
8 body: Center(
9 child: ElevatedButton(
10 onPressed: () {
11 // Pop and send data back
12 Navigator.pop(context, 'red');
13 },
14 child: const Text('Choose Red'),
15 ),
16 ),
17 );
18 }
19}
dart
1// ── On the calling screen (await for the result) ──
2class HomeScreen extends StatefulWidget {
3 @override
4 State<HomeScreen> createState() => _HomeScreenState();
5}
6
7class _HomeScreenState extends State<HomeScreen> {
8 String _selectedColor = 'none';
9
10 Future<void> _openColorPicker() async {
11 // await the result from the pushed screen
12 final result = await Navigator.push<String>(
13 context,
14 MaterialPageRoute(builder: (_) => const ColorPickerScreen()),
15 );
16
17 // result is null if user pressed back without selecting
18 if (result != null) {
19 setState(() => _selectedColor = result);
20 }
21 }
22
23 @override
24 Widget build(BuildContext context) {
25 return Scaffold(
26 body: Column(
27 children: [
28 Text('Selected: $_selectedColor'),
29 ElevatedButton(
30 onPressed: _openColorPicker,
31 child: const Text('Pick Color'),
32 ),
33 ],
34 ),
35 );
36 }
37}

Always handle null

💡 Always handle null

Navigator.push returns a Future that completes with `null` if the user pressed the back button without providing a result. Always check `if (result != null)` before using it.

Result-Driven Flows

Returned data is ideal for transient decisions such as pickers, confirmations, and quick editors.

This keeps screens loosely coupled: child screen decides output, parent screen decides how to use that output.

Async Return Pitfall

⚠️ Async Return Pitfall

If the parent screen is disposed before the awaited navigation result returns, avoid calling setState. Check mounted before updating UI state.

This Lesson In Simple Words

Pass data back to the previous screen after navigation. Navigation manages how users move between screens and return to previous states.

Your level focus

Connect each concept to real app features you can build.

One practical habit

Design route names and arguments before wiring screen UI.

Deep Understanding Guide

Why this lesson matters

Poor routing decisions create confusing UX and fragile deep-link behavior.

Study flow for better retention

  1. Map the lesson to one screen, one user action, and one expected output.
  2. Think user journey first: open app, enter data, recover state, continue flow.
  3. If you can choose between two approaches and explain why, you are improving.

Common Mistakes To Avoid

  • Passing very large objects through routes instead of IDs or lightweight models.
  • Mixing unrelated navigation methods in the same feature.
  • Losing state on back navigation due to poor route stack handling.
  • Not testing deep links and cold-start navigation paths.

Practice Sprint (15-25 Minutes)

  • Before running sample code, predict output and behavior in one sentence.
  • Implement a three-screen flow with named routes and typed arguments.
  • Add one deep-link path and verify expected destination.
  • Write a small route guard for authenticated vs guest users.
  • Complete the required exercises without using hints on the first attempt.
  • Answer this question out loud before checking quiz options: "How do you return data from a screen in Flutter?".

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 "Returning Data From 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: Passing very large objects through routes instead of IDs or lightweight models.
  • 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 do you return data from a screen in Flutter?

Navigator.pop(context, result) closes the screen and passes the result back to the awaiting Navigator.push call.

In the calling screen, what do you do to wait for the returned value?

await Navigator.push() waits for the pushed screen to be popped and returns its result. The calling function must be async.

What does Navigator.push return if the user presses the back button?

If the user navigates back without calling Navigator.pop(context, value), the Future completes with null.

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