Unverified Commit 67797182 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix scrolled under for 2D scrolling (#121297)

Fix AppBar scrolled under for 2D scrolling
parent 1bfba756
...@@ -768,8 +768,9 @@ class _AppBarState extends State<AppBar> { ...@@ -768,8 +768,9 @@ class _AppBarState extends State<AppBar> {
break; break;
case AxisDirection.right: case AxisDirection.right:
case AxisDirection.left: case AxisDirection.left:
// Scrolled under is only supported in the vertical axis. // Scrolled under is only supported in the vertical axis, and should
_scrolledUnder = false; // not be altered based on horizontal notifications of the same
// predicate since it could be a 2D scroller.
break; break;
} }
......
...@@ -3598,6 +3598,64 @@ void main() { ...@@ -3598,6 +3598,64 @@ void main() {
); );
} }
testWidgets('backgroundColor for horizontal scrolling', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
appBar: AppBar(
elevation: 0,
backgroundColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
return states.contains(MaterialState.scrolledUnder)
? scrolledColor
: defaultColor;
}),
title: const Text('AppBar'),
notificationPredicate: (ScrollNotification notification) {
// Represents both scroll views below being treated as a
// single viewport.
return notification.depth <= 1;
},
),
body: SingleChildScrollView(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
height: 1200,
width: 1200,
color: Colors.teal,
),
),
),
),
)
);
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(0.0, -kToolbarHeight));
await tester.pump();
await gesture.moveBy(const Offset(0.0, -kToolbarHeight));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), scrolledColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
gesture = await tester.startGesture(const Offset(50.0, 300.0));
// Scroll horizontally
await gesture.moveBy(const Offset(-kToolbarHeight, 0.0));
await tester.pump();
await gesture.moveBy(const Offset(-kToolbarHeight, 0.0));
await gesture.up();
await tester.pumpAndSettle();
// The app bar is still scrolled under vertically, so it should not have
// changed back in response to horizontal scrolling.
expect(getAppBarBackgroundColor(tester), scrolledColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
});
testWidgets('backgroundColor', (WidgetTester tester) async { testWidgets('backgroundColor', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
buildAppBar(contentHeight: 1200.0) buildAppBar(contentHeight: 1200.0)
......
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