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
610ca324
Unverified
Commit
610ca324
authored
Sep 24, 2021
by
Kate Lovett
Committed by
GitHub
Sep 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update scrollbar for hover events (#90636)
parent
126370fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
21 deletions
+63
-21
scrollbar.dart
packages/flutter/lib/src/widgets/scrollbar.dart
+28
-21
scrollbar_test.dart
packages/flutter/test/widgets/scrollbar_test.dart
+35
-0
No files found.
packages/flutter/lib/src/widgets/scrollbar.dart
View file @
610ca324
...
...
@@ -462,29 +462,37 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
break
;
}
// Whether we paint or not, calculating these rects allows us to hit test
// when the scrollbar is transparent.
_trackRect
=
trackOffset
&
trackSize
;
canvas
.
drawRect
(
_trackRect
!,
_paintTrack
());
canvas
.
drawLine
(
trackOffset
,
Offset
(
trackOffset
.
dx
,
trackOffset
.
dy
+
_trackExtent
),
_paintTrack
(
isBorder:
true
),
);
_thumbRect
=
Offset
(
x
,
y
)
&
thumbSize
;
if
(
radius
!=
null
)
{
canvas
.
drawRRect
(
RRect
.
fromRectAndRadius
(
_thumbRect
!,
radius
!),
_paintThumb
);
return
;
}
if
(
shape
==
null
)
{
canvas
.
drawRect
(
_thumbRect
!,
_paintThumb
);
return
;
// Paint if the opacity dictates visibility
if
(
fadeoutOpacityAnimation
.
value
!=
0.0
)
{
// Track
canvas
.
drawRect
(
_trackRect
!,
_paintTrack
());
// Track Border
canvas
.
drawLine
(
trackOffset
,
Offset
(
trackOffset
.
dx
,
trackOffset
.
dy
+
_trackExtent
),
_paintTrack
(
isBorder:
true
),
);
if
(
radius
!=
null
)
{
// Rounded rect thumb
canvas
.
drawRRect
(
RRect
.
fromRectAndRadius
(
_thumbRect
!,
radius
!),
_paintThumb
);
return
;
}
if
(
shape
==
null
)
{
// Square thumb
canvas
.
drawRect
(
_thumbRect
!,
_paintThumb
);
return
;
}
// Custom-shaped thumb
final
Path
outerPath
=
shape
!.
getOuterPath
(
_thumbRect
!);
canvas
.
drawPath
(
outerPath
,
_paintThumb
);
shape
!.
paint
(
canvas
,
_thumbRect
!);
}
final
Path
outerPath
=
shape
!.
getOuterPath
(
_thumbRect
!);
canvas
.
drawPath
(
outerPath
,
_paintThumb
);
shape
!.
paint
(
canvas
,
_thumbRect
!);
}
double
_thumbExtent
()
{
...
...
@@ -573,7 +581,6 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
void
paint
(
Canvas
canvas
,
Size
size
)
{
if
(
_lastAxisDirection
==
null
||
_lastMetrics
==
null
||
fadeoutOpacityAnimation
.
value
==
0.0
||
_lastMetrics
!.
maxScrollExtent
<=
_lastMetrics
!.
minScrollExtent
)
return
;
...
...
@@ -606,7 +613,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
/// be used.
bool
hitTestInteractive
(
Offset
position
,
PointerDeviceKind
kind
,
{
bool
forHover
=
false
})
{
if
(
_thumbRect
==
null
)
{
// We have n
ever painted the scrollbar, so we do not know where it will be
.
// We have n
ot computed the scrollbar position yet
.
return
false
;
}
...
...
packages/flutter/test/widgets/scrollbar_test.dart
View file @
610ca324
...
...
@@ -883,6 +883,41 @@ void main() {
);
});
testWidgets
(
'Scrollbar will show on hover without needing to scroll first for metrics'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
MediaQuery
(
data:
MediaQueryData
(),
child:
RawScrollbar
(
child:
SingleChildScrollView
(
child:
SizedBox
(
width:
4000.0
,
height:
4000.0
),
),
),
),
),
);
await
tester
.
pump
();
// Hover over scrollbar with mouse. Even though we have not scrolled, the
// ScrollMetricsNotification will have informed the Scrollbar's hit testing.
final
TestGesture
mouseGesture
=
await
tester
.
createGesture
(
kind:
ui
.
PointerDeviceKind
.
mouse
);
await
mouseGesture
.
addPointer
();
addTearDown
(
mouseGesture
.
removePointer
);
await
mouseGesture
.
moveTo
(
const
Offset
(
794.0
,
5.0
));
await
tester
.
pumpAndSettle
();
// Scrollbar should have appeared in response to hover event.
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
,
0.0
,
800.0
,
90.0
),
color:
const
Color
(
0x66BCBCBC
),
),
);
});
testWidgets
(
'Scrollbar thumb can be dragged'
,
(
WidgetTester
tester
)
async
{
final
ScrollController
scrollController
=
ScrollController
();
await
tester
.
pumpWidget
(
...
...
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