Skip to content

Allow depending on ModalRoute.popDispositionOf(context) #162009

Closed

Description

@timcreatedit

Use case

I want to implement a custom widget that can close the current route using a gesture. One of my requirements is that the gesture is not accepted, if the current route can't be popped using a gesture (aka its popDisposition is .doNotPop).

Unfortunately, I found no way to keep my widget updated, since depending on ModalRoute.of(context) doesn't trigger a rebuild when the popDisposition changes, and its Notifications bubble upwards, so the route's contents can't receive them.

Proposal

Add popDisposition as an aspect to the respective InheritedModel so that we can depend on it reliably.

Activity

  1. added
    in triagePresently being triaged by the triage team
    c: new featureNothing broken; request for a new capability
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: routesNavigator, Router, and related APIs.
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Jan 23, 2025
  2. maRci002 commented on Jan 23, 2025

    @maRci002
    Contributor

    You can create your own NotificationListener<NavigationNotification>. Here is an example from the framework:

    child: NotificationListener<NavigationNotification>(
    onNotification: (NavigationNotification notification) {
    // If the state of this Navigator does not change whether or not the
    // whole framework can pop, propagate the Notification as-is.
    if (notification.canHandlePop || !canPop()) {
    return false;
    }
    // Otherwise, dispatch a new Notification with the correct canPop and
    // stop the propagation of the old Notification.
    const NavigationNotification nextNotification = NavigationNotification(
    canHandlePop: true,
    );
    nextNotification.dispatch(context);
    return true;
    },

  3. timcreatedit commented on Jan 23, 2025

    @timcreatedit
    ContributorAuthor

    Hi @maRci002, thanks for the swift response! I don't think this is a viable solution, since Notifications only bubble upwards, while I want to know the route's popDisposition from it's subtree (any widget that's part of a route's content).

    Let me know if I'm misunderstanding something.

  4. added
    P3Issues that are less important to the Flutter project
    on Jan 28, 2025
  5. added a commit that references this issue on May 29, 2025
    df29894
  6. added a commit that references this issue on May 29, 2025
    3ec43c7
  7. github-actions commented on Jun 12, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: routesNavigator, Router, and related APIs.frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions