Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Expose padding on RawScrollbar #107756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/flutter/lib/src/widgets/scrollbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ class RawScrollbar extends StatefulWidget {
this.scrollbarOrientation,
this.mainAxisMargin = 0.0,
this.crossAxisMargin = 0.0,
this.padding,
@Deprecated(
'Use thumbVisibility instead. '
'This feature was deprecated after v2.9.0-1.0.pre.',
Expand Down Expand Up @@ -1366,6 +1367,13 @@ class RawScrollbar extends StatefulWidget {
/// Must not be null and defaults to 0.
final double crossAxisMargin;

/// The insets by which the scrollbar thumb and track should be padded.
///
/// When null, the inherited [MediaQueryData.padding] is used.
///
/// Defaults to null.
final EdgeInsets? padding;

@override
RawScrollbarState<RawScrollbar> createState() => RawScrollbarState<RawScrollbar>();
}
Expand Down Expand Up @@ -1593,7 +1601,7 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
..textDirection = Directionality.of(context)
..thickness = widget.thickness ?? _kScrollbarThickness
..radius = widget.radius
..padding = MediaQuery.of(context).padding
..padding = widget.padding ?? MediaQuery.of(context).padding
..scrollbarOrientation = widget.scrollbarOrientation
..mainAxisMargin = widget.mainAxisMargin
..shape = widget.shape
Expand Down
36 changes: 34 additions & 2 deletions packages/flutter/test/widgets/scrollbar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2612,7 +2612,7 @@ void main() {
// Go without throw.
});

testWidgets('Track offset respects padding', (WidgetTester tester) async {
testWidgets('Track offset respects MediaQuery padding', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/106834
final ScrollController scrollController = ScrollController();
await tester.pumpWidget(
Expand Down Expand Up @@ -2640,7 +2640,39 @@ void main() {
find.byType(RawScrollbar),
paints
..rect(rect: const Rect.fromLTRB(744.0, 50.0, 750.0, 550.0)) // track
..rect(rect: const Rect.fromLTRB(744.0, 50.0, 750.0, 71.0))
..rect(rect: const Rect.fromLTRB(744.0, 50.0, 750.0, 71.0)) // thumb
); // thumb
});

testWidgets('RawScrollbar.padding replaces MediaQueryData.padding', (WidgetTester tester) async {
final ScrollController scrollController = ScrollController();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(
padding: EdgeInsets.all(50.0),
),
child: RawScrollbar(
controller: scrollController,
minThumbLength: 21,
minOverscrollLength: 8,
thumbVisibility: true,
padding: const EdgeInsets.all(100),
child: SingleChildScrollView(
controller: scrollController,
child: const SizedBox(width: 1000.0, height: 50000.0),
),
),
)
)
);
await tester.pumpAndSettle();
expect(
find.byType(RawScrollbar),
paints
..rect(rect: const Rect.fromLTRB(694.0, 100.0, 700.0, 500.0)) // track
..rect(rect: const Rect.fromLTRB(694.0, 100.0, 700.0, 121.0)) // thumb
); // thumb
});
}