Commit 529c25ca authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Update the AppBar scroll offset only if the body region is scrolled (#5343)

Fixes https://github.com/flutter/flutter/issues/5131
parent 803fbec5
......@@ -681,7 +681,18 @@ class ScaffoldState extends State<Scaffold> {
}
final List<LayoutId> children = new List<LayoutId>();
_addIfNonNull(children, config.body, _ScaffoldSlot.body);
Widget body;
if (config.appBarBehavior != AppBarBehavior.anchor) {
body = new NotificationListener<ScrollNotification>(
onNotification: _handleScrollNotification,
child: config.body
);
} else {
body = config.body;
}
_addIfNonNull(children, body, _ScaffoldSlot.body);
if (config.appBarBehavior == AppBarBehavior.anchor) {
final double expandedHeight = (config.appBar?.expandedHeight ?? 0.0) + padding.top;
final Widget appBar = new ConstrainedBox(
......@@ -728,27 +739,15 @@ class ScaffoldState extends State<Scaffold> {
));
}
Widget application;
if (config.appBarBehavior != AppBarBehavior.anchor) {
application = new NotificationListener<ScrollNotification>(
onNotification: _handleScrollNotification,
child: new CustomMultiChildLayout(
EdgeInsets appPadding = (config.appBarBehavior != AppBarBehavior.anchor) ?
EdgeInsets.zero : padding;
Widget application = new CustomMultiChildLayout(
children: children,
delegate: new _ScaffoldLayout(
padding: EdgeInsets.zero,
padding: appPadding,
appBarBehavior: config.appBarBehavior
)
)
);
} else {
application = new CustomMultiChildLayout(
children: children,
delegate: new _ScaffoldLayout(
padding: padding
)
);
}
return new Material(child: application);
}
......
......@@ -76,4 +76,56 @@ void main() {
expect(tester.binding.transientCallbackCount, greaterThan(0));
});
testWidgets('Drawer scrolling', (WidgetTester tester) async {
GlobalKey<ScrollableState<Scrollable>> drawerKey =
new GlobalKey<ScrollableState<Scrollable>>(debugLabel: 'drawer');
Key appBarKey = new Key('appBar');
const double appBarHeight = 256.0;
await tester.pumpWidget(
new MaterialApp(
home: new Scaffold(
appBarBehavior: AppBarBehavior.under,
appBar: new AppBar(
key: appBarKey,
expandedHeight: appBarHeight,
title: new Text('Title'),
flexibleSpace: new FlexibleSpaceBar(title: new Text('Title')),
),
drawer: new Drawer(
child: new Block(
scrollableKey: drawerKey,
children: new List<Widget>.generate(10,
(int index) => new SizedBox(height: 100.0, child: new Text('D$index'))
)
)
),
body: new Block(
padding: const EdgeInsets.only(top: appBarHeight),
children: new List<Widget>.generate(10,
(int index) => new SizedBox(height: 100.0, child: new Text('B$index'))
),
),
)
)
);
ScaffoldState state = tester.firstState(find.byType(Scaffold));
state.openDrawer();
await tester.pump();
await tester.pump(const Duration(seconds: 1));
expect(drawerKey.currentState.scrollOffset, equals(0));
const double scrollDelta = 80.0;
await tester.scroll(find.byKey(drawerKey), const Offset(0.0, -scrollDelta));
await tester.pump();
expect(drawerKey.currentState.scrollOffset, equals(scrollDelta));
RenderBox renderBox = tester.renderObject(find.byKey(appBarKey));
expect(renderBox.size.height, equals(appBarHeight));
});
}
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