Skip to content

openDialog / openGeneralDialog should not force use of root Navigator #23565

Closed

Description

@josvos

I would like to have a useRootNavigator parameter (which may default to true to ensure backwards compatibility) for openDialog and openGeneralDialog, so that you have the option to use the nearest Navigator instance instead of the furthest one.

This would save me a lot of headaches for having to pass an extra context to my dialog (and further down in the tree) to access a useful context instead of the context of the top navigator.

Activity

  1. zoechi commented on Oct 27, 2018

    @zoechi
    Contributor

    headaches for having to pass an extra context

    what kind of headaches are those?

    Can you please provide a minimal reproduction that allows to understand your problem better?

    Please also add the output of flutter doctor -v.

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 27, 2018
  3. josvos commented on Oct 27, 2018

    @josvos
    Author

    The "headaches" are simply that I need the context of the nearest Navigator to find back my inherited widgets (incl. correct Theme etc.), that in my case aren't available in the context of the topmost Navigator. By explicitly passing the caller context to the modal widget as an extra parameter I am able to find them, but in case the modal is becoming more complex (using a larger tree with more generic widgets) this is no longer a viable solution.

    [✓] Flutter (Channel dev, v0.10.1, on Linux, locale en_US.UTF-8)
        • Flutter version 0.10.1 at /home/jos/flutter1/flutter
        • Framework revision 6a3ff018b1 (9 days ago), 2018-10-18 18:38:26 -0400
        • Engine revision 3860a43379
        • Dart version 2.1.0-dev.7.1.flutter-b99bcfd309
    
    [✓] Android toolchain - develop for Android devices (Android SDK 28.0.0)
        • Android SDK at /home/jos/Android/Sdk
        • Android NDK location not configured (optional; useful for native profiling
          support)
        • Platform android-28, build-tools 28.0.0
        • Java binary at: /home/jos/flutter1/android-studio/jre/bin/java
        • Java version OpenJDK Runtime Environment (build
          1.8.0_152-release-1024-b01)
        • All Android licenses accepted.
    
    [✓] Android Studio (version 3.1)
        • Android Studio at /home/jos/flutter1/android-studio
        • Flutter plugin version 27.1.1
        • Dart plugin version 173.4700
        • Java version OpenJDK Runtime Environment (build
          1.8.0_152-release-1024-b01)
    
  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 27, 2018
  5. added
    c: new featureNothing broken; request for a new capability
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: routesNavigator, Router, and related APIs.
    on Oct 27, 2018
  6. added this to the milestone on Oct 27, 2018
  7. shinayser commented on Jul 12, 2019

    @shinayser

    The current implementation of showDialog (and its variants) always pick the root navigator as below:

    Future<T> showGeneralDialog<T>({
      @required BuildContext context,
      @required RoutePageBuilder pageBuilder,
      bool barrierDismissible,
      String barrierLabel,
      Color barrierColor,
      Duration transitionDuration,
      RouteTransitionsBuilder transitionBuilder,
    }) {
      assert(pageBuilder != null);
      assert(!barrierDismissible || barrierLabel != null);
      return Navigator.of(context, rootNavigator: true).push<T>(_DialogRoute<T>( // <-- ROOT NAVIGATOR IS SET TO TRUE
        pageBuilder: pageBuilder,
        barrierDismissible: barrierDismissible,
        barrierLabel: barrierLabel,
        barrierColor: barrierColor,
        transitionDuration: transitionDuration,
        transitionBuilder: transitionBuilder,
      ));
    }

    This makes tedious and difficult to show dialogs inside other Navigatos that is not the default one, like this:

    image

    My suggestion is to change the signatures of showGeneralDialog and showDialog (and other related methods) to include an option parameter "useRootNavigator" that will be true as default so it will not break noone's code.

  8. roeierez commented on Aug 6, 2019

    @roeierez

    This makes tedious and difficult to show dialogs inside other Navigatos that is not the default one

    Totally agree. @shinayser how did you manage to show the dialog inside a nested navigator?

  9. shinayser commented on Aug 6, 2019

    @shinayser

    This makes tedious and difficult to show dialogs inside other Navigatos that is not the default one

    Totally agree. @shinayser how did you manage to show the dialog inside a nested navigator?

    I copy and pasted the code from showDialog and showGeneralDialog, wich contains the call to the Navigator.of(context, rootNavigator: true) passing false as the "rootNavigator".

  10. roeierez commented on Aug 6, 2019

    @roeierez

    @shinayser thanks for explaining.
    I really hope your suggestion will be accepted, I think it is good and a small change.
    In case someone from the team is looking for more motivation to fix this, my headache is that I would like to implement a PinCode screen that prompts the user when the app is resumed from background and I would like to push that screen to the root navigator, while the rest of the app is pushed in a nested navigator. It is the safest way I found to implement it without worrying that some dialog will be pushed on top of the PinCode screen due to unexpected event.
    This dialog behavior prevents me from doing it and makes me code lots of non elegant changes.

  11. github-actions commented on Aug 15, 2021

    @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.

  12. locked as resolved and limited conversation to collaborators on Aug 15, 2021
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

    c: new featureNothing broken; request for a new capabilityf: routesNavigator, Router, and related APIs.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions