D
NavigationEasy20 XP2 min read

How do you return a result from a pushed route?

TL;DR: Navigator.push returns a Future. Call Navigator.pop(context, result) on the child route to complete the Future with a value. In go_router, context.pop(result) does the same.

Full Answer

A common pattern is opening a selection screen and using the result on return. Navigator.push<T>() returns Future<T?>, which resolves when the route is popped with a value.

๐ŸŽฏ

Always handle the null case โ€” the user may press the back button without selecting anything, returning null.

Code Examples

dartReturning a result from a route
Output
Tapping 'Blue' in ColorPickerScreen returns Colors.blue to the caller; selected color is updated

Common Mistakes

  • โœ—Not awaiting Navigator.push โ€” the result Future is never read
  • โœ—Using go_router's context.go() instead of context.push() โ€” go() doesn't support result return

Interview Tip

๐Ÿ’ก

This is a common interview coding question. Showing you handle the null (back button) case demonstrates attention to edge cases.

#Navigator#pop-result#context.pop#go_router