-
Notifications
You must be signed in to change notification settings - Fork 29.7k
make some BuildContext methods generics #44189
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
Conversation
|
I really like this clean-up and the extra type safety it gives us. However, this looks like a rather big breaking change that will also break many users of flutter (see current cirrus failures as an example). I wonder if we can somehow do this change with a softer transition where we deprecate the existing API, but it continuous to work until our dependencies had a chance to upgrade to the new API. |
Me too :)
Yes :( but the upcoming NNBD will be way more breaking.
I planned to update scoped_model but I was wondering how to deal with that (flutter repo depends on scoped_model and scoped_model depends on flutter - perhaps make a git ref dependency on a fork of scoped_model until a new flutter version is out)
I thought about it and I didn't see a good solution:
I don't really know how often those methods are used outside of flutter but if someone has access to a corpus of code on pub it could be really interesting to grab some datas on the usage of those methods. WDYT? |
e4233e8 to
d1fcbba
Compare
|
It's now green with a patched version of scoped_model. |
|
Can we make this less breaking by deprecating these versions and instead adding new methods with different (more uniform?) names that use the new style? e.g. we could add "find" to those that are O(N), to make it clearer that they're more expensive. I'm not sure exactly what to do with the O(1) ones...
|
|
I like the suggestion regarding the "find". Here are my suggestions for the other two. I am hoping that "depend" makes it more clearer than "inherit" that you're adding a dependency on the InheritedWidget and get rebuilt whenever it changes. The other method's name just adopted to that naming scheme and the "get" sets it apart from the "find" in terms of lookup performance. inheritFromWidgetOfExactType -> dependOnInheritedWidgetOfExactType |
|
Let me know what the other 2 methods should become. |
d1fcbba to
5f2b8ca
Compare
|
@goderbauer's proposals LGTM. |
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.
nit: add a . add the end.
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 elsewhere.
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.
Also: insead -> instead.
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.
Done
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.
Also: The doc comment for this method should just say that this method is deprecated and point to the new method (no need to duplicate the doc 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.
Here and elsewhere.
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.
Done.
The doc comment for this method should just say that this method is deprecated and point to the new method (no need to duplicate the doc comment).
I only left the first sentence.
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.
Name this getElementForInheritedWidgetOfExactType (I edited my suggestion shortly after posting, sorry if you only saw the old 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.
Renamed.
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 should probably mark TypeMatcher as deprecated as well since that will go away as soon as we delete the old deprecated API?
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.
Done.
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.
Can we implement the old API by calling the new API to avoid duplication?
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.
Unfortunately not in this direction (the new can be implemented with the old) because we cannot extract T from Type.
analysis_options.yaml
Outdated
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.
Can you add a comment explaining why this is commented out?
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.
I shouldn't have checked that in. Removed.
|
I believe you may have to pull in the latest master to turn the tests green. |
5f2b8ca to
3477b1f
Compare
This reverts commit d1fcbba028cdb07f44738d1652391692d1ea5ec0.
7f3df90 to
e30a4fd
Compare
|
@rrousselGit thanks for your suggestions. I'll let @Hixie and @goderbauer comment on them (all the prefixes look good to me except get*) |
|
@a14n Looks like the announcement is showing up here now: https://groups.google.com/forum/#!topic/flutter-announce/RS82mg9iK24 |
goderbauer
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
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.
It looks like for this test it wouldn't matter, so I would prefer the simplified version.
|
(PR triage): @a14n Is this one good to go? |
Yes. I'm only waiting for a green tree. |
|
This pull request is not suitable for automatic merging in its current state.
|
Description
Several methods in
BuildContextwere usingTypeto search for ancestor.inheritFromWidgetOfExactTypeancestorInheritedElementForWidgetOfExactTypeancestorWidgetOfExactTypeancestorStateOfTyperootAncestorStateOfTypeancestorRenderObjectOfTypeMost of those methods implied a cast at call site because their return type was a parent type. Moreover the type provided was not checked at analysis time even if the type is actually constrainted.
Making those methods generics improves type safety and need less code.
Related Issues
None
Tests
None because it's a refactoring.
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
Does your PR require Flutter developers to manually update their apps to accommodate your change?