diff --git a/packages/flutter/lib/src/widgets/scroll_notification.dart b/packages/flutter/lib/src/widgets/scroll_notification.dart index 683717946c..f0a2bfb0b5 100644 --- a/packages/flutter/lib/src/widgets/scroll_notification.dart +++ b/packages/flutter/lib/src/widgets/scroll_notification.dart @@ -144,7 +144,12 @@ class ScrollUpdateNotification extends ScrollNotification { required BuildContext context, this.dragDetails, this.scrollDelta, - }) : super(metrics: metrics, context: context); + int? depth, + }) : super(metrics: metrics, context: context) { + if (depth != null) { + _depth = depth; + } + } /// If the [Scrollable] changed its scroll position because of a drag, the /// details about that drag update. diff --git a/packages/flutter/lib/src/widgets/scrollbar.dart b/packages/flutter/lib/src/widgets/scrollbar.dart index c24a787095..9ecd6ae8a4 100644 --- a/packages/flutter/lib/src/widgets/scrollbar.dart +++ b/packages/flutter/lib/src/widgets/scrollbar.dart @@ -1550,7 +1550,11 @@ class RawScrollbarState extends State with TickerProv } bool _handleScrollMetricsNotification(ScrollMetricsNotification notification) { - if (!widget.notificationPredicate(ScrollUpdateNotification(metrics: notification.metrics, context: notification.context))) + if (!widget.notificationPredicate(ScrollUpdateNotification( + metrics: notification.metrics, + context: notification.context, + depth: notification.depth, + ))) return false; if (showScrollbar) { diff --git a/packages/flutter/test/widgets/scrollbar_test.dart b/packages/flutter/test/widgets/scrollbar_test.dart index 7adc699f1b..e9f40b8559 100644 --- a/packages/flutter/test/widgets/scrollbar_test.dart +++ b/packages/flutter/test/widgets/scrollbar_test.dart @@ -1708,4 +1708,37 @@ void main() { ), ); }); + + testWidgets('notificationPredicate depth test.', (WidgetTester tester) async { + final ScrollController scrollController = ScrollController(); + final List depths = []; + Widget buildFrame() { + return Directionality( + textDirection: TextDirection.ltr, + child: MediaQuery( + data: const MediaQueryData(), + child: RawScrollbar( + notificationPredicate: (ScrollNotification notification) { + depths.add(notification.depth); + return notification.depth == 0; + }, + controller: scrollController, + isAlwaysShown: true, + child: SingleChildScrollView( + controller: scrollController, + child: const SingleChildScrollView(), + ), + ), + ), + ); + } + await tester.pumpWidget(buildFrame()); + await tester.pumpAndSettle(); + + // `notificationPredicate` should be called twice with different `depth` + // because there are two scrollable widgets. + expect(depths.length, 2); + expect(depths[0], 1); + expect(depths[1], 0); + }); }