Fix a Scrollbar hittest penetration issue (#99328)

This commit is contained in:
xubaolin
2022-03-03 02:26:23 +08:00
committed by GitHub
parent 7372ad17f6
commit 4b20ce74e3
2 changed files with 51 additions and 1 deletions

View File

@@ -736,6 +736,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
if (ignorePointer) {
return false;
}
// The thumb is not able to be hit when transparent.
if (fadeoutOpacityAnimation.value == 0.0) {
return false;
@@ -745,7 +746,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
return false;
}
return _thumbRect!.contains(position!);
return _trackRect!.contains(position!);
}
@override

View File

@@ -1345,6 +1345,55 @@ void main() {
);
});
testWidgets('hit test', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/99324
final ScrollController scrollController = ScrollController();
bool onTap = false;
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(),
child: PrimaryScrollController(
controller: scrollController,
child: RawScrollbar(
trackVisibility: true,
thumbVisibility: true,
controller: scrollController,
child: SingleChildScrollView(
child: GestureDetector(
onTap: () => onTap = true,
child: const SizedBox(
width: 4000.0,
height: 4000.0,
child: ColoredBox(color: Color(0x00000000)),
),
),
),
),
),
),
),
);
await tester.pumpAndSettle();
expect(onTap, false);
// Tap on track area.
await tester.tapAt(const Offset(795.0, 550.0));
await tester.pumpAndSettle();
expect(onTap, false);
// Tap on thumb area.
await tester.tapAt(const Offset(795.0, 10.0));
await tester.pumpAndSettle();
expect(onTap, false);
// Tap on content area.
await tester.tapAt(const Offset(400.0, 300.0));
await tester.pumpAndSettle();
expect(onTap, true);
});
testWidgets('RawScrollbar.thumbVisibility asserts that a ScrollPosition is attached', (WidgetTester tester) async {
final FlutterExceptionHandler? handler = FlutterError.onError;
FlutterErrorDetails? error;