forked from firka/flutter
Fix a CupertinoScrollbar NNBD issue (#111198)
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user