Unverified Commit e12c7516 authored by Rami's avatar Rami Committed by GitHub

Only trigger AppBar scrolledUnder state for vertical scrolling and not horizontal (#84268)

parent ae976665
......@@ -762,7 +762,9 @@ class _AppBarState extends State<AppBar> {
void _handleScrollNotification(ScrollNotification notification) {
if (notification is ScrollUpdateNotification) {
final bool oldScrolledUnder = _scrolledUnder;
_scrolledUnder = notification.depth == 0 && notification.metrics.extentBefore > 0;
_scrolledUnder = notification.depth == 0
&& notification.metrics.extentBefore > 0
&& notification.metrics.axis == Axis.vertical;
if (_scrolledUnder != oldScrolledUnder) {
setState(() {
// React to a change in MaterialState.scrolledUnder
......
......@@ -2910,6 +2910,56 @@ void main() {
expect(tester.takeException(), isNull);
});
testWidgets('AppBar scrolledUnder does not trigger on horizontal scroll', (WidgetTester tester) async {
const Color scrolledColor = Color(0xff00ff00);
const Color defaultColor = Color(0xff0000ff);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
appBar: AppBar(
backwardsCompatibility: false,
elevation: 0,
backgroundColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
return states.contains(MaterialState.scrolledUnder) ? scrolledColor : defaultColor;
}),
title: const Text('AppBar'),
),
body: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(height: 600.0, width: 1200.0, color: Colors.teal),
],
),
),
),
);
Finder findAppBarMaterial() {
return find.descendant(of: find.byType(AppBar), matching: find.byType(Material));
}
Color? getAppBarBackgroundColor() {
return tester.widget<Material>(findAppBarMaterial()).color;
}
expect(getAppBarBackgroundColor(), defaultColor);
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(-100.0, 0.0));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(), defaultColor);
gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(100.0, 0.0));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(), defaultColor);
});
testWidgets('AppBar.preferredHeightFor', (WidgetTester tester) async {
late double preferredHeight;
late Size preferredSize;
......
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