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
217cd102
Unverified
Commit
217cd102
authored
Jan 14, 2021
by
xubaolin
Committed by
GitHub
Jan 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix an assertion causes by zero offset pointer scroll (#73016)
parent
fc25d8b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
7 deletions
+49
-7
scrollable.dart
packages/flutter/lib/src/widgets/scrollable.dart
+8
-7
scrollable_test.dart
packages/flutter/test/widgets/scrollable_test.dart
+41
-0
No files found.
packages/flutter/lib/src/widgets/scrollable.dart
View file @
217cd102
...
...
@@ -629,8 +629,7 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
// Returns the offset that should result from applying [event] to the current
// position, taking min/max scroll extent into account.
double
_targetScrollOffsetForPointerScroll
(
PointerScrollEvent
event
)
{
final
double
delta
=
_pointerSignalEventDelta
(
event
);
double
_targetScrollOffsetForPointerScroll
(
double
delta
)
{
return
math
.
min
(
math
.
max
(
position
.
pixels
+
delta
,
position
.
minScrollExtent
),
position
.
maxScrollExtent
);
}
...
...
@@ -653,9 +652,10 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
if
(
_physics
!=
null
&&
!
_physics
!.
shouldAcceptUserOffset
(
position
))
{
return
;
}
final
double
targetScrollOffset
=
_targetScrollOffsetForPointerScroll
(
event
);
final
double
delta
=
_pointerSignalEventDelta
(
event
);
final
double
targetScrollOffset
=
_targetScrollOffsetForPointerScroll
(
delta
);
// Only express interest in the event if it would actually result in a scroll.
if
(
targetScrollOffset
!=
position
.
pixels
)
{
if
(
delta
!=
0.0
&&
targetScrollOffset
!=
position
.
pixels
)
{
GestureBinding
.
instance
!.
pointerSignalResolver
.
register
(
event
,
_handlePointerScroll
);
}
}
...
...
@@ -663,9 +663,10 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
void
_handlePointerScroll
(
PointerEvent
event
)
{
assert
(
event
is
PointerScrollEvent
);
final
double
targetScrollOffset
=
_targetScrollOffsetForPointerScroll
(
event
as
PointerScrollEvent
);
if
(
targetScrollOffset
!=
position
.
pixels
)
{
position
.
pointerScroll
(
_pointerSignalEventDelta
(
event
));
final
double
delta
=
_pointerSignalEventDelta
(
event
as
PointerScrollEvent
);
final
double
targetScrollOffset
=
_targetScrollOffsetForPointerScroll
(
delta
);
if
(
delta
!=
0.0
&&
targetScrollOffset
!=
position
.
pixels
)
{
position
.
pointerScroll
(
delta
);
}
}
...
...
packages/flutter/test/widgets/scrollable_test.dart
View file @
217cd102
...
...
@@ -1206,6 +1206,47 @@ void main() {
expect
(
outerController
.
position
.
pixels
,
0.0
);
expect
(
innerController
.
position
.
pixels
,
0.0
);
});
// Regression test for https://github.com/flutter/flutter/issues/71949
testWidgets
(
'Zero offset pointer scroll should not trigger an assertion.'
,
(
WidgetTester
tester
)
async
{
final
ScrollController
controller
=
ScrollController
();
Widget
build
(
double
height
)
{
return
MaterialApp
(
home:
Scaffold
(
body:
SizedBox
(
width:
double
.
infinity
,
height:
height
,
child:
SingleChildScrollView
(
controller:
controller
,
child:
const
SizedBox
(
width:
double
.
infinity
,
height:
300.0
,
),
),
)
),
);
}
await
tester
.
pumpWidget
(
build
(
200.0
));
expect
(
controller
.
position
.
pixels
,
0.0
);
controller
.
jumpTo
(
100.0
);
expect
(
controller
.
position
.
pixels
,
100.0
);
// Make the outer constraints larger that the scrollable widget is no longer able to scroll.
await
tester
.
pumpWidget
(
build
(
300.0
));
expect
(
controller
.
position
.
pixels
,
100.0
);
expect
(
controller
.
position
.
maxScrollExtent
,
0.0
);
// Hover over the scroll view and create a zero offset pointer scroll.
final
Offset
scrollable
=
tester
.
getCenter
(
find
.
byType
(
SingleChildScrollView
));
final
TestPointer
testPointer
=
TestPointer
(
1
,
ui
.
PointerDeviceKind
.
mouse
);
testPointer
.
hover
(
scrollable
);
await
tester
.
sendEventToBinding
(
testPointer
.
scroll
(
const
Offset
(
0.0
,
0.0
)));
expect
(
tester
.
takeException
(),
null
);
});
}
// ignore: must_be_immutable
...
...
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