Return a value from a screen
You want a screen — a picker, a form, a confirmation — to hand a typed value back to whoever opened it.
The recipe
Section titled “The recipe”Open the screen with pushForResult<T> and await:
final picked = await context.router<AppRoute>() .pushForResult<String>(const ColorPicker());
if (picked != null) { // The screen popped with a value.}Inside the screen, pop with the value:
FilledButton( onPressed: () => context.pop('teal'), child: const Text('Choose teal'),)nullmeans dismissed — the user backed out, or the screen left the stack another way. Treat it as a first-class outcome, not an error.- The screen is a normal main-stack route: observers see it, dialogs
render above it, system back works. If you need a multi-step flow
with its own sub-stack, use
run<T>instead — sameFuture<T?>shape, different home for the screens. - A pending result doesn’t survive process death (futures can’t be serialized) — don’t gate critical state on one. Details in the navigation reference.