Skip to content

[go_router] Support return data from a screen with pop() #99663

@dangngocduc

Description

@dangngocduc

Use case

With Navigator, we can push to new screen and await result.

    final result = await Navigator.push(
      context,
      // Create the SelectionScreen in the next step.
      MaterialPageRoute(builder: (context) => const SelectionScreen()),
    );
   

Currently go_router is support push, go but it return void.

  /// Navigate to a URI location w/ optional query parameters, e.g.
  /// `/family/f2/person/p1?color=blue`
  void go(String location, {Object? extra}) =>
      routerDelegate.go(location, extra: extra);
  /// Push a URI location onto the page stack w/ optional query parameters, e.g.
  /// `/family/f2/person/p1?color=blue`
  void push(String location, {Object? extra}) =>
      routerDelegate.push(location, extra: extra);

Expected Behaviour: push, go support return a Future and user can call pop with a result.

This is sample for this feature:

https://docs.flutter.dev/cookbook/navigation/returning-data

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions