...

/

Solution: Navigation and Routing

Solution: Navigation and Routing

Explore solutions to navigation challenges.

Solutions

Great job on completing all the steps in the previous challenge! Feel free to compare your code solutions with the solutions below:

Press + to interact
IconButton(
onPressed: () {
// TODO-1: Return data from screen below
// solution
Navigator.pop(context, shopItem.itemName);
},
icon: const Icon(
Icons.arrow_back,
size: 32,
),
),
GestureDetector(
// TODO-2: Display data received
// solution
onTap: () async{
var data = await Navigator.pushNamed(context, itemDetailRoute,arguments: shopList[index]);
ScaffoldMessenger.of(context)
..removeCurrentSnackBar()
..showSnackBar(SnackBar(content: Text('$data')));
},
child: ItemCard(
shopItem: shopList[index],
),
),
ElevatedButton(
onPressed: () {
// TODO-3: Clear routes to first screen
// solution
Navigator.popUntil(context, (route)=> route.isFirst);
},
...
)
...