Update the AppBar scroll offset only if the body region is scrolled (#5343)
Fixes https://github.com/flutter/flutter/issues/5131
This commit is contained in:
parent
803fbec51b
commit
529c25caa8
@ -681,7 +681,18 @@ class ScaffoldState extends State<Scaffold> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final List<LayoutId> children = new List<LayoutId>();
|
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) {
|
if (config.appBarBehavior == AppBarBehavior.anchor) {
|
||||||
final double expandedHeight = (config.appBar?.expandedHeight ?? 0.0) + padding.top;
|
final double expandedHeight = (config.appBar?.expandedHeight ?? 0.0) + padding.top;
|
||||||
final Widget appBar = new ConstrainedBox(
|
final Widget appBar = new ConstrainedBox(
|
||||||
@ -728,27 +739,15 @@ class ScaffoldState extends State<Scaffold> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget application;
|
EdgeInsets appPadding = (config.appBarBehavior != AppBarBehavior.anchor) ?
|
||||||
|
EdgeInsets.zero : padding;
|
||||||
if (config.appBarBehavior != AppBarBehavior.anchor) {
|
Widget application = new CustomMultiChildLayout(
|
||||||
application = new NotificationListener<ScrollNotification>(
|
|
||||||
onNotification: _handleScrollNotification,
|
|
||||||
child: new CustomMultiChildLayout(
|
|
||||||
children: children,
|
children: children,
|
||||||
delegate: new _ScaffoldLayout(
|
delegate: new _ScaffoldLayout(
|
||||||
padding: EdgeInsets.zero,
|
padding: appPadding,
|
||||||
appBarBehavior: config.appBarBehavior
|
appBarBehavior: config.appBarBehavior
|
||||||
)
|
)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
application = new CustomMultiChildLayout(
|
|
||||||
children: children,
|
|
||||||
delegate: new _ScaffoldLayout(
|
|
||||||
padding: padding
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Material(child: application);
|
return new Material(child: application);
|
||||||
}
|
}
|
||||||
|
@ -76,4 +76,56 @@ void main() {
|
|||||||
|
|
||||||
expect(tester.binding.transientCallbackCount, greaterThan(0));
|
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));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user