-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Add Directionality.maybeOf #69117
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
Add Directionality.maybeOf #69117
Conversation
| final ThemeData theme = Theme.of(context)!; | ||
| final ChipThemeData chipTheme = ChipTheme.of(context); | ||
| final TextDirection? textDirection = Directionality.of(context); | ||
| final TextDirection? textDirection = Directionality.maybeOf(context); |
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.
Here and below: should this really be nullable? I understand it was, but it might help to have a comment here about why we're allowing this to be null instead of using .of.
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.
Ultimately, they are passed to EdgeInsetsGeometry.resolve, which is fine with a null text direction as long as the EdgeInsetsGeometry is not text direction aware. Similar with the other cases.
We actually have tests for these. If you make it non-null here, they will fail.
| /// ```dart | ||
| /// TextDirection textDirection = Directionality.of(context); | ||
| /// ``` | ||
| // TODO(goderbauer): Make this non-null when customers have upgraded to Directionality.maybeOf. |
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.
Should we start encouraging people to migrate by adding an assert here with a message saying to use maybeOf if the resolved direction is null?
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.
That could be kinda spammy. I think we usually don't do that.
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.
Won't that effectively be what users gets though when we actually make this non-null? But probably without the benefit of a message printing next to the error that they really should use the other variant...
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.
We can make the error message link to TextDirection.maybeOf.
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.
How does that work for compile time errors?
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.
What do you mean? The assert added will be a runtime error.
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.
We will basically just call https://master-api.flutter.dev/flutter/widgets/debugCheckHasDirectionality.html at the beginning of this method.
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.
Discussed offline - most apps will get directionality from material/cupertinoapp, probably not worth worrying about outside of tests.
dnfield
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.
LGTM
Description
Adds
Directionality.maybeOf(and uses it in the framework) in preparation of makingDirectionality.ofnon-nullable. Making it non-nullable is not part of this PR since we first need to migrate some customers (flutter_svg) to the newmaybeOfAPI before we can do that.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.