Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit f852c46

Browse files
authored
Expose padding on RawScrollbar (#107756)
1 parent b5590a0 commit f852c46

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

packages/flutter/lib/src/widgets/scrollbar.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ class RawScrollbar extends StatefulWidget {
944944
this.scrollbarOrientation,
945945
this.mainAxisMargin = 0.0,
946946
this.crossAxisMargin = 0.0,
947+
this.padding,
947948
@Deprecated(
948949
'Use thumbVisibility instead. '
949950
'This feature was deprecated after v2.9.0-1.0.pre.',
@@ -1366,6 +1367,13 @@ class RawScrollbar extends StatefulWidget {
13661367
/// Must not be null and defaults to 0.
13671368
final double crossAxisMargin;
13681369

1370+
/// The insets by which the scrollbar thumb and track should be padded.
1371+
///
1372+
/// When null, the inherited [MediaQueryData.padding] is used.
1373+
///
1374+
/// Defaults to null.
1375+
final EdgeInsets? padding;
1376+
13691377
@override
13701378
RawScrollbarState<RawScrollbar> createState() => RawScrollbarState<RawScrollbar>();
13711379
}
@@ -1593,7 +1601,7 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
15931601
..textDirection = Directionality.of(context)
15941602
..thickness = widget.thickness ?? _kScrollbarThickness
15951603
..radius = widget.radius
1596-
..padding = MediaQuery.of(context).padding
1604+
..padding = widget.padding ?? MediaQuery.of(context).padding
15971605
..scrollbarOrientation = widget.scrollbarOrientation
15981606
..mainAxisMargin = widget.mainAxisMargin
15991607
..shape = widget.shape

packages/flutter/test/widgets/scrollbar_test.dart

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,7 +2612,7 @@ void main() {
26122612
// Go without throw.
26132613
});
26142614

2615-
testWidgets('Track offset respects padding', (WidgetTester tester) async {
2615+
testWidgets('Track offset respects MediaQuery padding', (WidgetTester tester) async {
26162616
// Regression test for https://github.com/flutter/flutter/issues/106834
26172617
final ScrollController scrollController = ScrollController();
26182618
await tester.pumpWidget(
@@ -2640,7 +2640,39 @@ void main() {
26402640
find.byType(RawScrollbar),
26412641
paints
26422642
..rect(rect: const Rect.fromLTRB(744.0, 50.0, 750.0, 550.0)) // track
2643-
..rect(rect: const Rect.fromLTRB(744.0, 50.0, 750.0, 71.0))
2643+
..rect(rect: const Rect.fromLTRB(744.0, 50.0, 750.0, 71.0)) // thumb
2644+
); // thumb
2645+
});
2646+
2647+
testWidgets('RawScrollbar.padding replaces MediaQueryData.padding', (WidgetTester tester) async {
2648+
final ScrollController scrollController = ScrollController();
2649+
await tester.pumpWidget(
2650+
Directionality(
2651+
textDirection: TextDirection.ltr,
2652+
child: MediaQuery(
2653+
data: const MediaQueryData(
2654+
padding: EdgeInsets.all(50.0),
2655+
),
2656+
child: RawScrollbar(
2657+
controller: scrollController,
2658+
minThumbLength: 21,
2659+
minOverscrollLength: 8,
2660+
thumbVisibility: true,
2661+
padding: const EdgeInsets.all(100),
2662+
child: SingleChildScrollView(
2663+
controller: scrollController,
2664+
child: const SizedBox(width: 1000.0, height: 50000.0),
2665+
),
2666+
),
2667+
)
2668+
)
2669+
);
2670+
await tester.pumpAndSettle();
2671+
expect(
2672+
find.byType(RawScrollbar),
2673+
paints
2674+
..rect(rect: const Rect.fromLTRB(694.0, 100.0, 700.0, 500.0)) // track
2675+
..rect(rect: const Rect.fromLTRB(694.0, 100.0, 700.0, 121.0)) // thumb
26442676
); // thumb
26452677
});
26462678
}

0 commit comments

Comments
 (0)