-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Make Directionality.of non-null #69060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Directionality.of non-null #69060
Conversation
This comment has been minimized.
This comment has been minimized.
|
Customer tests for flutter_svg are failing on this change. |
|
In google this change uncovered 6 buggy tests, which were accidentally passing with Directionality.of returning null even though they shouldn't. Fixes for that a purely in the test by adding a Directionality widget to them. One widget in google3 needs to have |
|
@dnfield @Hixie @gspencergoog Curious to hear what you think about this change. I think overall it improves the readability of the code by removing a lot of
At the same time, this change also uncovered 7 buggy tests in google, where the test authors forgot to include a Directionality widget (even though they should have). Overall, I am in favor of this change, but like I said, it is slightly breaking. |
|
Some of our If not, I think we might want to just add a If so, I think we should evaluate when it's ok for these to be null or not. It seems like we have API usages that expect this to be nullable. I'd probably be more in favor of adding some assert(s) to this so that tests have to opt in to a nullOk. I'm having trouble deciding whether this is really the right way to go - I can think of cases where you'd ask about the direcitionality of your context and be ok with it not existing, and other cases where you wouldn't. You can make that clear already by using |
|
@gspencergoog is working on removing the nullOk parameters from those other methods you mentioned. We will introduce maybeOf methods for those as well. |
|
I'm in favour of making every |
|
OK, I'm happy to expand mine to include all the others (I think I have most of them in my doc already). |
|
SGTM. In that case I'm in favor of this approach. |
|
Looks like we are in agreement on this change. Here's my plan for executing it:
The first step of this plan is #69117. @gspencergoog I will add these APIs to https://flutter.dev/go/eliminating-nullok-parameters so we remember to include them in the migration guide. |
e31848e to
c51e0ee
Compare
|
This PR now represents step 5 of the plan in my previous post. Submitting this is blocked on submitting dnfield/flutter_svg#435 first. |
gspencergoog
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mention that in debug mode it throws an assertion, and in release mode throws an exception.
Yeah, i still need to submit dnfield/flutter_svg#435 to make those happy. |
a78be9a to
23c66a4
Compare

Description
In the majority of cases we assume in the framework that
Directionality.ofreturns a non-null value. This PR changes the API of that method to guarantee a non-null return value (and throw if no Directionality can be found) to clean up those call sides. Additionally, it adds a newDirectionality.maybeOfmethod for those handful of cases, we a null return value is actually ok.I think overall this leads to cleaner code because in the cases where you don't expect
Directionality.ofto return null you can remove the!.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.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.