Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6779718

Browse files
authored
Fix scrolled under for 2D scrolling (#121297)
Fix AppBar scrolled under for 2D scrolling
1 parent 1bfba75 commit 6779718

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

packages/flutter/lib/src/material/app_bar.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,9 @@ class _AppBarState extends State<AppBar> {
768768
break;
769769
case AxisDirection.right:
770770
case AxisDirection.left:
771-
// Scrolled under is only supported in the vertical axis.
772-
_scrolledUnder = false;
771+
// Scrolled under is only supported in the vertical axis, and should
772+
// not be altered based on horizontal notifications of the same
773+
// predicate since it could be a 2D scroller.
773774
break;
774775
}
775776

packages/flutter/test/material/app_bar_test.dart

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3598,6 +3598,64 @@ void main() {
35983598
);
35993599
}
36003600

3601+
testWidgets('backgroundColor for horizontal scrolling', (WidgetTester tester) async {
3602+
await tester.pumpWidget(
3603+
MaterialApp(
3604+
home: Scaffold(
3605+
appBar: AppBar(
3606+
elevation: 0,
3607+
backgroundColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
3608+
return states.contains(MaterialState.scrolledUnder)
3609+
? scrolledColor
3610+
: defaultColor;
3611+
}),
3612+
title: const Text('AppBar'),
3613+
notificationPredicate: (ScrollNotification notification) {
3614+
// Represents both scroll views below being treated as a
3615+
// single viewport.
3616+
return notification.depth <= 1;
3617+
},
3618+
),
3619+
body: SingleChildScrollView(
3620+
child: SingleChildScrollView(
3621+
scrollDirection: Axis.horizontal,
3622+
child: Container(
3623+
height: 1200,
3624+
width: 1200,
3625+
color: Colors.teal,
3626+
),
3627+
),
3628+
),
3629+
),
3630+
)
3631+
);
3632+
3633+
expect(getAppBarBackgroundColor(tester), defaultColor);
3634+
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
3635+
3636+
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
3637+
await gesture.moveBy(const Offset(0.0, -kToolbarHeight));
3638+
await tester.pump();
3639+
await gesture.moveBy(const Offset(0.0, -kToolbarHeight));
3640+
await gesture.up();
3641+
await tester.pumpAndSettle();
3642+
3643+
expect(getAppBarBackgroundColor(tester), scrolledColor);
3644+
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
3645+
3646+
gesture = await tester.startGesture(const Offset(50.0, 300.0));
3647+
// Scroll horizontally
3648+
await gesture.moveBy(const Offset(-kToolbarHeight, 0.0));
3649+
await tester.pump();
3650+
await gesture.moveBy(const Offset(-kToolbarHeight, 0.0));
3651+
await gesture.up();
3652+
await tester.pumpAndSettle();
3653+
// The app bar is still scrolled under vertically, so it should not have
3654+
// changed back in response to horizontal scrolling.
3655+
expect(getAppBarBackgroundColor(tester), scrolledColor);
3656+
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
3657+
});
3658+
36013659
testWidgets('backgroundColor', (WidgetTester tester) async {
36023660
await tester.pumpWidget(
36033661
buildAppBar(contentHeight: 1200.0)

0 commit comments

Comments
 (0)