Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
2987d9e1
Unverified
Commit
2987d9e1
authored
Jul 14, 2022
by
Kate Lovett
Committed by
GitHub
Jul 14, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix scrollbar margins (#107172)
parent
c1846178
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
25 deletions
+37
-25
scrollbar.dart
packages/flutter/lib/src/widgets/scrollbar.dart
+30
-18
scrollbar_test.dart
packages/flutter/test/cupertino/scrollbar_test.dart
+3
-3
scrollbar_theme_test.dart
packages/flutter/test/material/scrollbar_theme_test.dart
+3
-3
scrollbar_test.dart
packages/flutter/test/widgets/scrollbar_test.dart
+1
-1
No files found.
packages/flutter/lib/src/widgets/scrollbar.dart
View file @
2987d9e1
...
...
@@ -211,8 +211,10 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
/// Mustn't be null.
final
Animation
<
double
>
fadeoutOpacityAnimation
;
/// Distance from the scrollbar's start and end to the edge of the viewport
/// in logical pixels. It affects the amount of available paint area.
/// Distance from the scrollbar thumb's start and end to the edge of the
/// viewport in logical pixels. It affects the amount of available paint area.
///
/// The scrollbar track consumes this space.
///
/// Mustn't be null and defaults to 0.
double
get
mainAxisMargin
=>
_mainAxisMargin
;
...
...
@@ -230,6 +232,8 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
/// Distance from the scrollbar thumb to the nearest cross axis edge
/// in logical pixels.
///
/// The scrollbar track consumes this space.
///
/// Must not be null and defaults to 0.
double
get
crossAxisMargin
=>
_crossAxisMargin
;
double
_crossAxisMargin
;
...
...
@@ -488,7 +492,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
trackSize
=
Size
(
thickness
+
2
*
crossAxisMargin
,
_trackExtent
);
x
=
crossAxisMargin
+
padding
.
left
;
y
=
_thumbOffset
;
trackOffset
=
Offset
(
x
-
crossAxisMargin
,
mainAxisMargin
+
padding
.
top
);
trackOffset
=
Offset
(
x
-
crossAxisMargin
,
padding
.
top
);
borderStart
=
trackOffset
+
Offset
(
trackSize
.
width
,
0.0
);
borderEnd
=
Offset
(
trackOffset
.
dx
+
trackSize
.
width
,
trackOffset
.
dy
+
_trackExtent
);
break
;
...
...
@@ -497,7 +501,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
trackSize
=
Size
(
thickness
+
2
*
crossAxisMargin
,
_trackExtent
);
x
=
size
.
width
-
thickness
-
crossAxisMargin
-
padding
.
right
;
y
=
_thumbOffset
;
trackOffset
=
Offset
(
x
-
crossAxisMargin
,
mainAxisMargin
+
padding
.
top
);
trackOffset
=
Offset
(
x
-
crossAxisMargin
,
padding
.
top
);
borderStart
=
trackOffset
;
borderEnd
=
Offset
(
trackOffset
.
dx
,
trackOffset
.
dy
+
_trackExtent
);
break
;
...
...
@@ -506,7 +510,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
trackSize
=
Size
(
_trackExtent
,
thickness
+
2
*
crossAxisMargin
);
x
=
_thumbOffset
;
y
=
crossAxisMargin
+
padding
.
top
;
trackOffset
=
Offset
(
mainAxisMargin
+
padding
.
left
,
y
-
crossAxisMargin
);
trackOffset
=
Offset
(
padding
.
left
,
y
-
crossAxisMargin
);
borderStart
=
trackOffset
+
Offset
(
0.0
,
trackSize
.
height
);
borderEnd
=
Offset
(
trackOffset
.
dx
+
_trackExtent
,
trackOffset
.
dy
+
trackSize
.
height
);
break
;
...
...
@@ -515,7 +519,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
trackSize
=
Size
(
_trackExtent
,
thickness
+
2
*
crossAxisMargin
);
x
=
_thumbOffset
;
y
=
size
.
height
-
thickness
-
crossAxisMargin
-
padding
.
bottom
;
trackOffset
=
Offset
(
mainAxisMargin
+
padding
.
left
,
y
-
crossAxisMargin
);
trackOffset
=
Offset
(
padding
.
left
,
y
-
crossAxisMargin
);
borderStart
=
trackOffset
;
borderEnd
=
Offset
(
trackOffset
.
dx
+
_trackExtent
,
trackOffset
.
dy
);
break
;
...
...
@@ -564,12 +568,12 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
1.0
);
final
double
thumbExtent
=
math
.
max
(
math
.
min
(
_trackExtent
,
minOverscrollLength
),
_trackExtent
*
fractionVisible
,
math
.
min
(
_tra
versableTra
ckExtent
,
minOverscrollLength
),
_tra
versableTra
ckExtent
*
fractionVisible
,
);
final
double
fractionOverscrolled
=
1.0
-
_lastMetrics
!.
extentInside
/
_lastMetrics
!.
viewportDimension
;
final
double
safeMinLength
=
math
.
min
(
minLength
,
_trackExtent
);
final
double
safeMinLength
=
math
.
min
(
minLength
,
_tra
versableTra
ckExtent
);
final
double
newMinLength
=
(
_beforeExtent
>
0
&&
_afterExtent
>
0
)
// Thumb extent is no smaller than minLength if scrolling normally.
?
safeMinLength
...
...
@@ -588,7 +592,8 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
// The `thumbExtent` should be no greater than `trackSize`, otherwise
// the scrollbar may scroll towards the wrong direction.
return
clampDouble
(
thumbExtent
,
newMinLength
,
_trackExtent
);
final
double
extent
=
clampDouble
(
thumbExtent
,
newMinLength
,
_traversableTrackExtent
);
return
extent
;
}
@override
...
...
@@ -604,8 +609,10 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
double
get
_afterExtent
=>
_isReversed
?
_lastMetrics
!.
extentBefore
:
_lastMetrics
!.
extentAfter
;
// Padding of the thumb track.
double
get
_mainAxisPadding
=>
_isVertical
?
padding
.
vertical
:
padding
.
horizontal
;
// The size of the thumb track.
double
get
_trackExtent
=>
_lastMetrics
!.
viewportDimension
-
2
*
mainAxisMargin
-
_mainAxisPadding
;
// The length of the painted track.
double
get
_trackExtent
=>
_lastMetrics
!.
viewportDimension
-
_mainAxisPadding
;
// The length of the track that is traversable by the thumb.
double
get
_traversableTrackExtent
=>
_trackExtent
-
(
2
*
mainAxisMargin
);
// The total size of the scrollable content.
double
get
_totalContentExtent
{
...
...
@@ -621,7 +628,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
double
getTrackToScroll
(
double
thumbOffsetLocal
)
{
assert
(
thumbOffsetLocal
!=
null
);
final
double
scrollableExtent
=
_lastMetrics
!.
maxScrollExtent
-
_lastMetrics
!.
minScrollExtent
;
final
double
thumbMovableExtent
=
_trackExtent
-
_thumbExtent
();
final
double
thumbMovableExtent
=
_tra
versableTra
ckExtent
-
_thumbExtent
();
return
scrollableExtent
*
thumbOffsetLocal
/
thumbMovableExtent
;
}
...
...
@@ -635,7 +642,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
?
clampDouble
((
metrics
.
pixels
-
metrics
.
minScrollExtent
)
/
scrollableExtent
,
0.0
,
1.0
)
:
0
;
return
(
_isReversed
?
1
-
fractionPast
:
fractionPast
)
*
(
_trackExtent
-
thumbExtent
);
return
(
_isReversed
?
1
-
fractionPast
:
fractionPast
)
*
(
_tra
versableTra
ckExtent
-
thumbExtent
);
}
@override
...
...
@@ -647,7 +654,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
}
// Skip painting if there's not enough space.
if
(
_lastMetrics
!.
viewportDimension
<=
_mainAxisPadding
||
_trackExtent
<=
0
)
{
if
(
_lastMetrics
!.
viewportDimension
<=
_mainAxisPadding
||
_tra
versableTra
ckExtent
<=
0
)
{
return
;
}
...
...
@@ -1342,15 +1349,20 @@ class RawScrollbar extends StatefulWidget {
/// {@macro flutter.widgets.Scrollbar.scrollbarOrientation}
final
ScrollbarOrientation
?
scrollbarOrientation
;
/// Distance from the scrollbar's start and end to the edge of the viewport
/// in logical pixels. It affects the amount of available paint area.
/// Distance from the scrollbar thumb's start or end to the nearest edge of
/// the viewport in logical pixels. It affects the amount of available
/// paint area.
///
/// The scrollbar track consumes this space.
///
/// Mustn't be null and defaults to 0.
final
double
mainAxisMargin
;
/// Distance from the scrollbar thumb side to the nearest cross axis edge
/// Distance from the scrollbar thumb
's
side to the nearest cross axis edge
/// in logical pixels.
///
/// The scrollbar track consumes this space.
///
/// Must not be null and defaults to 0.
final
double
crossAxisMargin
;
...
...
packages/flutter/test/cupertino/scrollbar_test.dart
View file @
2987d9e1
...
...
@@ -1230,11 +1230,11 @@ void main() {
find
.
byType
(
CupertinoScrollbar
),
paints
..
rect
(
rect:
const
Rect
.
fromLTRB
(
0.0
,
3.0
,
9.0
,
597
.0
),
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
9.0
,
600
.0
),
)
..
line
(
p1:
const
Offset
(
9.0
,
3
.0
),
p2:
const
Offset
(
9.0
,
597
.0
),
p1:
const
Offset
(
9.0
,
0
.0
),
p2:
const
Offset
(
9.0
,
600
.0
),
strokeWidth:
1.0
,
)
..
rrect
(
...
...
packages/flutter/test/material/scrollbar_theme_test.dart
View file @
2987d9e1
...
...
@@ -179,12 +179,12 @@ void main() {
find
.
byType
(
Scrollbar
),
paints
..
rect
(
rect:
const
Rect
.
fromLTRB
(
770.0
,
10.0
,
800.0
,
59
0.0
),
rect:
const
Rect
.
fromLTRB
(
770.0
,
0.0
,
800.0
,
60
0.0
),
color:
const
Color
(
0xff000000
),
)
..
line
(
p1:
const
Offset
(
770.0
,
1
0.0
),
p2:
const
Offset
(
770.0
,
59
0.0
),
p1:
const
Offset
(
770.0
,
0
0.0
),
p2:
const
Offset
(
770.0
,
60
0.0
),
strokeWidth:
1.0
,
color:
const
Color
(
0xffffeb3b
),
)
...
...
packages/flutter/test/widgets/scrollbar_test.dart
View file @
2987d9e1
...
...
@@ -1779,7 +1779,7 @@ void main() {
expect
(
find
.
byType
(
RawScrollbar
),
paints
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
10.0
,
800.0
,
59
0.0
))
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
0.0
,
800.0
,
60
0.0
))
..
rect
(
rect:
const
Rect
.
fromLTRB
(
794.0
,
10.0
,
800.0
,
358.0
))
);
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment