Unverified Commit a4b724d9 authored by xubaolin's avatar xubaolin Committed by GitHub

fix a scrollbar updating bug (#88152)

parent c49eba6c
......@@ -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.
......
......@@ -1550,7 +1550,11 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> 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) {
......
......@@ -1708,4 +1708,37 @@ void main() {
),
);
});
testWidgets('notificationPredicate depth test.', (WidgetTester tester) async {
final ScrollController scrollController = ScrollController();
final List<int> depths = <int>[];
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);
});
}
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