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
7bbcdc23
Unverified
Commit
7bbcdc23
authored
Aug 05, 2021
by
Kate Lovett
Committed by
GitHub
Aug 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent Scrollbar axis flipping when there is an oriented scroll controller (#87698)
parent
3dd81601
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
3 deletions
+91
-3
scrollbar.dart
packages/flutter/lib/src/widgets/scrollbar.dart
+30
-3
scrollbar_test.dart
packages/flutter/test/widgets/scrollbar_test.dart
+61
-0
No files found.
packages/flutter/lib/src/widgets/scrollbar.dart
View file @
7bbcdc23
...
...
@@ -1533,15 +1533,36 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
);
}
// ScrollController takes precedence over ScrollNotification
bool
_shouldUpdatePainter
(
Axis
notificationAxis
)
{
final
ScrollController
?
scrollController
=
widget
.
controller
??
PrimaryScrollController
.
of
(
context
);
// Only update the painter of this scrollbar if the notification
// metrics do not conflict with the information we have from the scroll
// controller.
return
// We do not have a scroll controller dictating axis.
scrollController
==
null
// The scroll controller is not attached to a position.
||
!
scrollController
.
hasClients
// The notification matches the scroll controller's axis.
||
scrollController
.
position
.
axis
==
notificationAxis
;
}
bool
_handleScrollMetricsNotification
(
ScrollMetricsNotification
notification
)
{
if
(!
widget
.
notificationPredicate
(
ScrollUpdateNotification
(
metrics:
notification
.
metrics
,
context:
notification
.
context
)))
return
false
;
if
(
showScrollbar
)
{
if
(
_fadeoutAnimationController
.
status
!=
AnimationStatus
.
forward
&&
_fadeoutAnimationController
.
status
!=
AnimationStatus
.
completed
)
_fadeoutAnimationController
.
forward
();
}
scrollbarPainter
.
update
(
notification
.
metrics
,
notification
.
metrics
.
axisDirection
);
final
ScrollMetrics
metrics
=
notification
.
metrics
;
if
(
_shouldUpdatePainter
(
metrics
.
axis
))
{
scrollbarPainter
.
update
(
metrics
,
metrics
.
axisDirection
);
}
return
false
;
}
...
...
@@ -1555,7 +1576,10 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
if
(
_fadeoutAnimationController
.
status
!=
AnimationStatus
.
dismissed
&&
_fadeoutAnimationController
.
status
!=
AnimationStatus
.
reverse
)
_fadeoutAnimationController
.
reverse
();
scrollbarPainter
.
update
(
metrics
,
metrics
.
axisDirection
);
if
(
_shouldUpdatePainter
(
metrics
.
axis
))
{
scrollbarPainter
.
update
(
metrics
,
metrics
.
axisDirection
);
}
return
false
;
}
...
...
@@ -1567,7 +1591,10 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
_fadeoutAnimationController
.
forward
();
_fadeoutTimer
?.
cancel
();
scrollbarPainter
.
update
(
notification
.
metrics
,
notification
.
metrics
.
axisDirection
);
if
(
_shouldUpdatePainter
(
metrics
.
axis
))
{
scrollbarPainter
.
update
(
metrics
,
metrics
.
axisDirection
);
}
}
else
if
(
notification
is
ScrollEndNotification
)
{
if
(
_dragScrollbarAxisOffset
==
null
)
_maybeStartFadeoutTimer
();
...
...
packages/flutter/test/widgets/scrollbar_test.dart
View file @
7bbcdc23
...
...
@@ -1637,4 +1637,65 @@ void main() {
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
RawScrollbar
),
isNot
(
paints
..
rect
()));
// Not shown.
});
testWidgets
(
'Scrollbar will not flip axes based on notification is there is a scroll controller'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/87697
final
ScrollController
verticalScrollController
=
ScrollController
();
final
ScrollController
horizontalScrollController
=
ScrollController
();
Widget
buildFrame
()
{
return
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
MediaQuery
(
data:
const
MediaQueryData
(),
child:
RawScrollbar
(
isAlwaysShown:
true
,
controller:
verticalScrollController
,
// This scrollbar will receive scroll notifications from both nested
// scroll views of opposite axes, but should stay on the vertical
// axis that its scroll controller is associated with.
notificationPredicate:
(
ScrollNotification
notification
)
=>
notification
.
depth
<=
1
,
child:
SingleChildScrollView
(
controller:
verticalScrollController
,
child:
SingleChildScrollView
(
scrollDirection:
Axis
.
horizontal
,
controller:
horizontalScrollController
,
child:
const
SizedBox
(
width:
1000.0
,
height:
1000.0
,
),
),
),
),
),
);
}
await
tester
.
pumpWidget
(
buildFrame
());
await
tester
.
pumpAndSettle
();
expect
(
verticalScrollController
.
offset
,
0.0
);
expect
(
horizontalScrollController
.
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
,
0.0
,
800.0
,
360.0
),
color:
const
Color
(
0x66BCBCBC
),
),
);
// Move the horizontal scroll view. The vertical scrollbar should not flip.
horizontalScrollController
.
jumpTo
(
10.0
);
expect
(
verticalScrollController
.
offset
,
0.0
);
expect
(
horizontalScrollController
.
offset
,
10.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
,
0.0
,
800.0
,
360.0
),
color:
const
Color
(
0x66BCBCBC
),
),
);
});
}
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