Repository navigation
Scaffold appBar is-a PreferredSizeWidget, etc - #9380
Conversation
There was a problem hiding this comment.
Oops, good catch, I missed that one.
There was a problem hiding this comment.
add some color, e.g. mention that Scaffold uses this?
There was a problem hiding this comment.
maybe explicitly point to PreferredSizeWidget.preferredSize, saying that this implements that interface?
There was a problem hiding this comment.
please inline this assert and make the constructor const while you're here.
Inlining asserts and making Widget constructors const where possible is the new "add a trailing comma" of code reviews.
There was a problem hiding this comment.
add docs similar to AppBar.preferredSize ?
There was a problem hiding this comment.
"PreferredSizeWidget" is confusing because this is not strictly a widget. I think maybe "PreferredSizeInterface" or "PreferredSizeProvider" or some such?
There was a problem hiding this comment.
i think this would be less confusing if it was abstract class PreferredSizeProvider extends Object implements Widget.
There was a problem hiding this comment.
Interface for Widgets that can...
There was a problem hiding this comment.
Oh I got confused, never mind.
There was a problem hiding this comment.
I didn't get confused. I think this should start off as "Interface for Widgets that can return the size this widget would prefer if...".
There was a problem hiding this comment.
also see:
* [PreferredSizeWidget], the interface which this widget implements to expose the preferred size.
* [AppBar] and [TabBar], which implement that same interface.
|
This approach is great. LGTM. |
2eba372 to
5b79c40
Compare
Requiring a Scaffold's appBar to be an AppBar widget was at least inconvenient and definitely inconsistent with the overall Flutter API. Similarly the bottom of an AppBar had to be a widget that implemented AppBarBottomWidget; somewhat less of an obstacle but still odd.
These quirks in the API existed because sometimes it's useful for a widget to advertise its preferred default size without actually constraining its own size.
The PreferredSizeWidget interface can be used for these situations. AppBar and TabBar implement PreferredSizeWidget:
In both cases the returned size only limits the height, like
new Size.fromHeight(100.0).Scaffold's
appBarand AppBar'sbottomproperties are now PreferredSizeWidgets. In the common cases where appBar is an AppBar and bottom is a TabBar, nothing needs to change.To substitute an abitrary widget for PreferredSizeWidget, use PreferredSize. For example:
Scaffold now has a default-true primary property, like AppBar does. If true then the height of the [appBar] will be extended by the height of the screen's status bar. Apps that set the Scaffold's primary property to false will very likely also want to set the appBar's property to false.
The AppBar
minExtentproperty has been replaced by preferredSize.Fixes: #8970
Fixes: #9349