Unverified Commit 9be0fa74 authored by xubaolin's avatar xubaolin Committed by GitHub

Fix a CupertinoScrollbar NNBD issue (#111198)

parent bcc1dc6b
......@@ -185,7 +185,10 @@ class _CupertinoScrollbarState extends RawScrollbarState<CupertinoScrollbar> {
@override
void handleThumbPressStart(Offset localPosition) {
super.handleThumbPressStart(localPosition);
final Axis direction = getScrollbarDirection()!;
final Axis? direction = getScrollbarDirection();
if (direction == null) {
return;
}
switch (direction) {
case Axis.vertical:
_pressStartAxisPosition = localPosition.dy;
......
......@@ -1060,6 +1060,50 @@ void main() {
);
});
testWidgets('Throw if interactive with the bar when no position attached', (WidgetTester tester) async {
final ScrollController scrollController = ScrollController();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(),
child: CupertinoScrollbar(
controller: scrollController,
thumbVisibility: true,
child: SingleChildScrollView(
controller: scrollController,
child: const SizedBox(
height: 1000.0,
width: 1000.0,
),
),
),
),
),
);
await tester.pumpAndSettle();
final ScrollPosition position = scrollController.position;
scrollController.detach(position);
final FlutterExceptionHandler? handler = FlutterError.onError;
FlutterErrorDetails? error;
FlutterError.onError = (FlutterErrorDetails details) {
error = details;
};
// long press the thumb
await tester.startGesture(const Offset(796.0, 50.0));
await tester.pump(kLongPressDuration);
expect(error, isNotNull);
scrollController.attach(position);
FlutterError.onError = handler;
});
testWidgets('Interactive scrollbars should have a valid scroll controller', (WidgetTester tester) async {
final ScrollController primaryScrollController = ScrollController();
final ScrollController scrollController = ScrollController();
......
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