Skip to content

Add "navigator" option to "showDialog" and "showGeneralDialog" - #42842

Merged
Piinks merged 5 commits into
flutter:masterfrom
brianegan:dialog-navigator
Nov 1, 2019
Merged

Piinks merged 5 commits into
flutter:masterfrom
brianegan:dialog-navigator

Conversation

@brianegan

@brianegan brianegan commented Oct 16, 2019 •

Copy link
Copy Markdown
Contributor

Description

The problem: We need to use showDialog to push a dialog to sub Navigator, not the root Navigator. At the moment, showDialog uses showGenericDialog which always uses the root navigator.

The solution: This Pull Request adds the ability to specify the NavigatorState which should be used to push dialog routes.

Alternative solution: Accept an optional bool useRootNavigator = true parameter instead of a NavigatorState.

Related Issues

Tests

I added the following tests:

  • Before writing tests I wanted feedback on the general idea. Tests will be added after completing any necessary api discussions.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@fluttergithubbot fluttergithubbot added the p: material_ui material_ui package in flutter/packages label Oct 16, 2019
@fluttergithubbot

Copy link
Copy Markdown
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Oct 16, 2019
@brianegan brianegan changed the title Add navigator option to showDialog and showGeneralDialog Add "navigator" option to "showDialog" and "showGeneralDialog" Oct 16, 2019

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach seems OK. This will need a test, though.

@Piinks Piinks added c: new feature Nothing broken; request for a new capability f: routes Navigator, Router, and related APIs. labels Oct 17, 2019

@jimmy-robert jimmy-robert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about other showXXX() functions that also use Navigator or showDialog?

  • showAboutDialog
  • showCupertinoDialog
  • showCupertinoModalPopup
  • showLicensePage
  • showMenu
  • showModalBottomSheet
  • showSearch
  • showTimePicker

@Piinks Piinks removed the p: material_ui material_ui package in flutter/packages label Oct 25, 2019
@Piinks

Piinks commented Oct 25, 2019

Copy link
Copy Markdown
Contributor

@brianegan Are you planning on revisiting this?

@brianegan

Copy link
Copy Markdown
Contributor Author

@Piinks Yep! Sorry, had another bit of work to wrap up the past week or so.

After seeing @JimmyRobz comment, I realized this is actually a pretty decent sized change to quite a few methods. Since the assets-for-api-docs project is quite unique in how it works and is kind of "non-standard", I wanted to take a bit more time to see if I could get around the issue without changing so many methods in Flutter itself.

After spending a few more hours on that, I think I feel pretty confident in saying the only way to fix the issue there is to make this change!

@brianegan

brianegan commented Oct 29, 2019 •

Copy link
Copy Markdown
Contributor Author

@JimmyRobz @goderbauer Thanks for your feedback! I have a question I'd love to ask: Is a NavigatorState navigator argument better than a bool useRootNavigator argument?

There were two ideas for this change -- allow this function to accept a bool useRootNavigator argument, or allow these functions to accept a specific NavigatorState navigator. @goderbauer suggested we go with the NavigatorState option, but while going through each showX method, I noticed the showModalBottomSheet already has a useRootNavigator option.

useRootNavigator

Pros:

  • API consistency with what's already in place
  • No need to remove @required annotation from context on several methods. Overall, I worry about removing that annotation and replacing it with an assert, since the annotation provides IDE completion / warnings whereas asserts only fail at runtime.

Cons:

  • Can't specify the exact navigator you want to use. Need to rely on the nearest Navigator.

NavigatorState

Pros:

  • Specify the exact NavigatorState you want to use

Cons:

  • Requires removing @required annotation
  • Maybe confusing to pass either a context or navigator into the function? Some methods would require both to get the desired effect.

@goderbauer

Copy link
Copy Markdown
Member

Since we already have useRootNavigator on one of them and we don't really have a user case for anything else I'd be fine with just adding useRootNavigator.

@brianegan

Copy link
Copy Markdown
Contributor Author

Thanks @goderbauer -- I've now changed everything to useRootNavigator. I've also added 1 test to the showDialog test suite. Could you please verify that's the correct / best way to test this change? If it looks ok or you have improvements, I can apply a similar test to all functions.

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just some nits.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should mention what the default is (here and elsewhere).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to use a {@macro ...} for this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned the default for every function.

I decided against a macro for now since there isn't much duplication and I find macro docs quite inconvenient as a user (since it forces you to leave your editor and head to the api docs website in order to view the information).

Let me know if you feel strongly about using @macro, though -- can be easily changed.

  - Tests for each function
  - Mention `useRootNavigator` default in every function's docs
  - Assert root navigator is not null in every function
  - Ensure correct default values for every function
@brianegan

Copy link
Copy Markdown
Contributor Author

Thanks again, @goderbauer. I've added tests to each function and addressed all feedback.

  - Mention useRootNavigator default in every function's docs
  - Assert root navigator is not null in every function
  - Ensure correct default values for every function

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@brianegan

Copy link
Copy Markdown
Contributor Author

Thanks, @goderbauer! Should I hold off on merging this change since flutter-build is currently broken on this branch? Is there anything I can do to fix it or is the problem unrelated to my changes?

@goderbauer

Copy link
Copy Markdown
Member

Yeah, you'll have to wait until all checks are green. The current redness is unrelated to your change.

@Piinks
Piinks merged commit 2e41483 into flutter:master Nov 1, 2019
@brianegan
brianegan deleted the dialog-navigator branch November 5, 2019 10:51
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Nov 26, 2019
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

c: new feature Nothing broken; request for a new capability f: routes Navigator, Router, and related APIs. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openDialog / openGeneralDialog should not force use of root Navigator

6 participants