diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 06d4afcc60..7c86924718 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -681,7 +681,18 @@ class ScaffoldState extends State { } final List children = new List(); - _addIfNonNull(children, config.body, _ScaffoldSlot.body); + + Widget body; + if (config.appBarBehavior != AppBarBehavior.anchor) { + body = new NotificationListener( + 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 { )); } - Widget application; - - if (config.appBarBehavior != AppBarBehavior.anchor) { - application = new NotificationListener( - onNotification: _handleScrollNotification, - child: new CustomMultiChildLayout( - children: children, - delegate: new _ScaffoldLayout( - padding: EdgeInsets.zero, - appBarBehavior: config.appBarBehavior - ) - ) - ); - } else { - application = new CustomMultiChildLayout( - children: children, - delegate: new _ScaffoldLayout( - padding: padding - ) - ); - } + EdgeInsets appPadding = (config.appBarBehavior != AppBarBehavior.anchor) ? + EdgeInsets.zero : padding; + Widget application = new CustomMultiChildLayout( + children: children, + delegate: new _ScaffoldLayout( + padding: appPadding, + appBarBehavior: config.appBarBehavior + ) + ); return new Material(child: application); } diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index 84bd2999b3..9ea19f7cb2 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -76,4 +76,56 @@ void main() { expect(tester.binding.transientCallbackCount, greaterThan(0)); }); + + testWidgets('Drawer scrolling', (WidgetTester tester) async { + GlobalKey> drawerKey = + new GlobalKey>(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.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.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)); + }); }