Commit 04e02059 authored by Hans Muller's avatar Hans Muller

Use _ScaffoldLayout to position scrollable appbars

parent f4603f76
...@@ -50,13 +50,15 @@ class GalleryHome extends StatefulWidget { ...@@ -50,13 +50,15 @@ class GalleryHome extends StatefulWidget {
} }
class GalleryHomeState extends State<GalleryHome> { class GalleryHomeState extends State<GalleryHome> {
final Key _scrollableKey = new UniqueKey(); final Key _homeKey = new ValueKey<String>("Gallery Home");
final Key _listKey = new ValueKey<String>("Gallery List");
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final double statusBarHight = (MediaQuery.of(context)?.padding ?? EdgeInsets.zero).top; final double statusBarHight = (MediaQuery.of(context)?.padding ?? EdgeInsets.zero).top;
return new Scaffold( return new Scaffold(
key: _homeKey,
drawer: new GalleryDrawer(), drawer: new GalleryDrawer(),
appBar: new AppBar( appBar: new AppBar(
expandedHeight: _kFlexibleSpaceMaxHeight, expandedHeight: _kFlexibleSpaceMaxHeight,
...@@ -65,13 +67,12 @@ class GalleryHomeState extends State<GalleryHome> { ...@@ -65,13 +67,12 @@ class GalleryHomeState extends State<GalleryHome> {
title: new Text("Flutter Gallery") title: new Text("Flutter Gallery")
) )
), ),
scrollableKey: _scrollableKey, scrollableKey: _listKey,
appBarBehavior: AppBarBehavior.under, appBarBehavior: AppBarBehavior.under,
body: new TwoLevelList( body: new TwoLevelList(
scrollablePadding: new EdgeInsets.only(top: _kFlexibleSpaceMaxHeight + statusBarHight), scrollablePadding: new EdgeInsets.only(top: _kFlexibleSpaceMaxHeight + statusBarHight),
key: _scrollableKey,
type: MaterialListType.oneLine, type: MaterialListType.oneLine,
scrollableKey: _scrollableKey, scrollableKey: _listKey,
items: <Widget>[ items: <Widget>[
new TwoLevelSublist( new TwoLevelSublist(
leading: new Icon(icon: Icons.star), leading: new Icon(icon: Icons.star),
......
...@@ -50,9 +50,10 @@ enum _ScaffoldSlot { ...@@ -50,9 +50,10 @@ enum _ScaffoldSlot {
} }
class _ScaffoldLayout extends MultiChildLayoutDelegate { class _ScaffoldLayout extends MultiChildLayoutDelegate {
_ScaffoldLayout({ this.padding }); _ScaffoldLayout({ this.padding, this.appBarBehavior: AppBarBehavior.anchor });
final EdgeInsets padding; final EdgeInsets padding;
final AppBarBehavior appBarBehavior;
@override @override
void performLayout(Size size) { void performLayout(Size size) {
...@@ -68,7 +69,9 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { ...@@ -68,7 +69,9 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate {
double contentBottom = size.height - padding.bottom; double contentBottom = size.height - padding.bottom;
if (hasChild(_ScaffoldSlot.appBar)) { if (hasChild(_ScaffoldSlot.appBar)) {
contentTop = layoutChild(_ScaffoldSlot.appBar, fullWidthConstraints).height; final double appBarHeight = layoutChild(_ScaffoldSlot.appBar, fullWidthConstraints).height;
if (appBarBehavior == AppBarBehavior.anchor)
contentTop = appBarHeight;
positionChild(_ScaffoldSlot.appBar, Offset.zero); positionChild(_ScaffoldSlot.appBar, Offset.zero);
} }
...@@ -522,6 +525,8 @@ class ScaffoldState extends State<Scaffold> { ...@@ -522,6 +525,8 @@ class ScaffoldState extends State<Scaffold> {
constraints: new BoxConstraints(maxHeight: expandedHeight) constraints: new BoxConstraints(maxHeight: expandedHeight)
); );
_addIfNonNull(children, appBar, _ScaffoldSlot.appBar); _addIfNonNull(children, appBar, _ScaffoldSlot.appBar);
} else {
children.add(new LayoutId(child: _buildScrollableAppBar(context), id: _ScaffoldSlot.appBar));
} }
// Otherwise the AppBar will be part of a [app bar, body] Stack. See AppBarBehavior.scroll below. // Otherwise the AppBar will be part of a [app bar, body] Stack. See AppBarBehavior.scroll below.
...@@ -565,21 +570,12 @@ class ScaffoldState extends State<Scaffold> { ...@@ -565,21 +570,12 @@ class ScaffoldState extends State<Scaffold> {
if (config.appBarBehavior != AppBarBehavior.anchor) { if (config.appBarBehavior != AppBarBehavior.anchor) {
application = new NotificationListener<ScrollNotification>( application = new NotificationListener<ScrollNotification>(
onNotification: _handleScrollNotification, onNotification: _handleScrollNotification,
child: new Stack( child: new CustomMultiChildLayout(
children: <Widget> [
new CustomMultiChildLayout(
children: children, children: children,
delegate: new _ScaffoldLayout( delegate: new _ScaffoldLayout(
padding: EdgeInsets.zero padding: EdgeInsets.zero,
) appBarBehavior: config.appBarBehavior
),
new Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
child: _buildScrollableAppBar(context)
) )
]
) )
); );
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment