mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
fix a scrollbar bug (#95894)
This commit is contained in:
parent
1bd8b58015
commit
02bf594f36
@ -1432,7 +1432,7 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.macOS:
|
||||
case TargetPlatform.windows:
|
||||
newPosition = newPosition.clamp(0.0, position.maxScrollExtent);
|
||||
newPosition = newPosition.clamp(position.minScrollExtent, position.maxScrollExtent);
|
||||
break;
|
||||
case TargetPlatform.iOS:
|
||||
case TargetPlatform.android:
|
||||
|
||||
@ -2075,6 +2075,87 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
testWidgets('Scrollbar thumb can be dragged when the scrollable widget has a negative minScrollExtent', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/95840
|
||||
|
||||
final ScrollController scrollController = ScrollController();
|
||||
final UniqueKey uniqueKey = UniqueKey();
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: MediaQuery(
|
||||
data: const MediaQueryData(),
|
||||
child: ScrollConfiguration(
|
||||
behavior: const ScrollBehavior().copyWith(
|
||||
scrollbars: false,
|
||||
),
|
||||
child: PrimaryScrollController(
|
||||
controller: scrollController,
|
||||
child: RawScrollbar(
|
||||
isAlwaysShown: true,
|
||||
controller: scrollController,
|
||||
child: CustomScrollView(
|
||||
center: uniqueKey,
|
||||
slivers: <Widget>[
|
||||
SliverToBoxAdapter(
|
||||
child: Container(
|
||||
height: 600.0,
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
key: uniqueKey,
|
||||
child: Container(
|
||||
height: 600.0,
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Container(
|
||||
height: 600.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(scrollController.offset, 0.0);
|
||||
expect(
|
||||
find.byType(RawScrollbar),
|
||||
paints
|
||||
..rect(rect: const Rect.fromLTRB(794.0, 0.0, 800.0, 600.0))
|
||||
..rect(
|
||||
rect: const Rect.fromLTRB(794.0, 200.0, 800.0, 400.0),
|
||||
color: const Color(0x66BCBCBC),
|
||||
),
|
||||
);
|
||||
|
||||
// Drag the thumb up to scroll up.
|
||||
const double scrollAmount = -10.0;
|
||||
final TestGesture dragScrollbarGesture = await tester.startGesture(const Offset(797.0, 300.0));
|
||||
await tester.pumpAndSettle();
|
||||
await dragScrollbarGesture.moveBy(const Offset(0.0, scrollAmount));
|
||||
await tester.pumpAndSettle();
|
||||
await dragScrollbarGesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The view has scrolled more than it would have by a swipe gesture of the
|
||||
// same distance.
|
||||
expect(scrollController.offset, lessThan(scrollAmount * 2));
|
||||
expect(
|
||||
find.byType(RawScrollbar),
|
||||
paints
|
||||
..rect(rect: const Rect.fromLTRB(794.0, 0.0, 800.0, 600.0))
|
||||
..rect(
|
||||
rect: const Rect.fromLTRB(794.0, 190.0, 800.0, 390.0),
|
||||
color: const Color(0x66BCBCBC),
|
||||
),
|
||||
);
|
||||
}, variant: TargetPlatformVariant.all());
|
||||
|
||||
test('ScrollbarPainter.shouldRepaint returns true when any of the properties changes', () {
|
||||
ScrollbarPainter createPainter({
|
||||
Color color = const Color(0xFF000000),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user