How can you pass data back when navigating back?
Navigator.pop() accepts an optional second argument that is returned to the previous screen.
Send and receive data when navigating
Passing the Quiz & Exercises is mandatory to earn FX and proceed. If you fail, try again to gain the required FX, then the Proceed button will become available.
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
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
There are several ways to pass data between screens in Flutter.
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.
1// Pass data via constructor2class ProductScreen extends StatelessWidget {3final String productId;4final String productName;56const ProductScreen({7required this.productId,8required this.productName,9});1011@override12Widget build(BuildContext context) {13return Scaffold(14appBar: AppBar(title: Text(productName)),15body: Text('Product ID: $productId'),16);17}18}1920// Navigate with data21Navigator.push(22context,23MaterialPageRoute(24builder: (context) => ProductScreen(25productId: '123',26productName: 'Flutter Course',27),28),29);
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.
1// Navigate with arguments2Navigator.pushNamed(3context,4'/product',5arguments: {'id': '123', 'name': 'Flutter Course'},6);78// Receive arguments in the screen9class ProductScreen extends StatelessWidget {10@override11Widget build(BuildContext context) {12// Extract arguments13final args = ModalRoute.of(context)!.settings.arguments14as Map<String, dynamic>;1516return Scaffold(17appBar: AppBar(title: Text(args['name'])),18body: Text('ID: ${args['id']}'),19);20}21}
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.
1// Screen that returns data2class SelectColorScreen extends StatelessWidget {3@override4Widget build(BuildContext context) {5return Scaffold(6body: Column(7children: [8ListTile(9title: Text('Red'),10onTap: () => Navigator.pop(context, 'red'),11),12ListTile(13title: Text('Blue'),14onTap: () => Navigator.pop(context, 'blue'),15),16],17),18);19}20}2122// Navigate and await result23void selectColor() async {24final selectedColor = await Navigator.push<String>(25context,26MaterialPageRoute(builder: (context) => SelectColorScreen()),27);2829if (selectedColor != null) {30print('User selected: $selectedColor');31}32}
Pick data passing style based on complexity:
Prefer typed model objects over loose maps whenever possible, because typed contracts catch mistakes earlier.
Send and receive data when navigating. This lesson adds one more building block for creating stable and user-friendly Flutter apps.
Connect each concept to real app features you can build.
After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.
Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.
Navigator.pop() accepts an optional second argument that is returned to the previous screen.
Navigator.push() returns a Future that resolves with the value passed to pop().
ModalRoute.of(context)!.settings.arguments retrieves the arguments passed via pushNamed.
Passing data via constructor is the simplest and most direct way to send data to a new screen.
Something seems incorrect, unclear, or missing? Let us know.
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