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
f1d04a46
Unverified
Commit
f1d04a46
authored
Aug 17, 2023
by
Chinmoy
Committed by
GitHub
Aug 17, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update `Scrollable` on `ScrollBehaviour` change. (#131164)
Fixes: #130793
parent
9e67e0e4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
113 additions
and
0 deletions
+113
-0
scrollable.dart
packages/flutter/lib/src/widgets/scrollable.dart
+6
-0
scrollable_test.dart
packages/flutter/test/widgets/scrollable_test.dart
+107
-0
No files found.
packages/flutter/lib/src/widgets/scrollable.dart
View file @
f1d04a46
...
...
@@ -632,6 +632,12 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
}
bool
_shouldUpdatePosition
(
Scrollable
oldWidget
)
{
if
((
widget
.
scrollBehavior
==
null
)
!=
(
oldWidget
.
scrollBehavior
==
null
))
{
return
true
;
}
if
(
widget
.
scrollBehavior
!=
null
&&
oldWidget
.
scrollBehavior
!=
null
&&
widget
.
scrollBehavior
!.
shouldNotify
(
oldWidget
.
scrollBehavior
!))
{
return
true
;
}
ScrollPhysics
?
newPhysics
=
widget
.
physics
??
widget
.
scrollBehavior
?.
getScrollPhysics
(
context
);
ScrollPhysics
?
oldPhysics
=
oldWidget
.
physics
??
oldWidget
.
scrollBehavior
?.
getScrollPhysics
(
context
);
do
{
...
...
packages/flutter/test/widgets/scrollable_test.dart
View file @
f1d04a46
...
...
@@ -1356,6 +1356,113 @@ void main() {
'AlwaysScrollableScrollPhysics ClampingScrollPhysics RangeMaintainingScrollPhysics'
,
);
});
testWidgets
(
'dragDevices change updates widget'
,
(
WidgetTester
tester
)
async
{
bool
enable
=
false
;
await
tester
.
pumpWidget
(
Builder
(
builder:
(
BuildContext
context
)
{
return
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
MaterialApp
(
home:
Scaffold
(
body:
Scrollable
(
scrollBehavior:
const
MaterialScrollBehavior
().
copyWith
(
dragDevices:
<
ui
.
PointerDeviceKind
>{
if
(
enable
)
ui
.
PointerDeviceKind
.
mouse
,
}),
viewportBuilder:
(
BuildContext
context
,
ViewportOffset
position
)
=>
Viewport
(
offset:
position
,
slivers:
const
<
Widget
>[
SliverToBoxAdapter
(
child:
SizedBox
(
height:
2000.0
)),
],
),
),
floatingActionButton:
FloatingActionButton
(
onPressed:
()
{
setState
(()
{
enable
=
!
enable
;
});
}),
),
);
},
);
},
)
);
// Gesture should not work.
TestGesture
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
byType
(
Scrollable
),
warnIfMissed:
true
),
kind:
ui
.
PointerDeviceKind
.
mouse
);
expect
(
getScrollOffset
(
tester
),
0.0
);
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
200
));
await
tester
.
pumpAndSettle
();
expect
(
getScrollOffset
(
tester
),
0.0
);
// Change state to include mouse pointer device.
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
pump
();
// Gesture should work after state change.
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
byType
(
Scrollable
),
warnIfMissed:
true
),
kind:
ui
.
PointerDeviceKind
.
mouse
);
expect
(
getScrollOffset
(
tester
),
0.0
);
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
200
));
await
tester
.
pumpAndSettle
();
expect
(
getScrollOffset
(
tester
),
200
);
});
testWidgets
(
'dragDevices change updates widget when oldWidget scrollBehavior is null'
,
(
WidgetTester
tester
)
async
{
ScrollBehavior
?
scrollBehavior
;
await
tester
.
pumpWidget
(
Builder
(
builder:
(
BuildContext
context
)
{
return
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
MaterialApp
(
home:
Scaffold
(
body:
Scrollable
(
physics:
const
ScrollPhysics
(),
scrollBehavior:
scrollBehavior
,
viewportBuilder:
(
BuildContext
context
,
ViewportOffset
position
)
=>
Viewport
(
offset:
position
,
slivers:
const
<
Widget
>[
SliverToBoxAdapter
(
child:
SizedBox
(
height:
2000.0
)),
],
),
),
floatingActionButton:
FloatingActionButton
(
onPressed:
()
{
setState
(()
{
scrollBehavior
=
const
MaterialScrollBehavior
().
copyWith
(
dragDevices:
<
ui
.
PointerDeviceKind
>{
ui
.
PointerDeviceKind
.
mouse
});
});
}),
),
);
},
);
},
)
);
// Gesture should not work.
TestGesture
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
byType
(
Scrollable
),
warnIfMissed:
true
),
kind:
ui
.
PointerDeviceKind
.
mouse
);
expect
(
getScrollOffset
(
tester
),
0.0
);
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
200
));
await
tester
.
pumpAndSettle
();
expect
(
getScrollOffset
(
tester
),
0.0
);
// Change state to include mouse pointer device.
await
tester
.
tap
(
find
.
byType
(
FloatingActionButton
));
await
tester
.
pump
();
// Gesture should work after state change.
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
byType
(
Scrollable
),
warnIfMissed:
true
),
kind:
ui
.
PointerDeviceKind
.
mouse
);
expect
(
getScrollOffset
(
tester
),
0.0
);
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
200
));
await
tester
.
pumpAndSettle
();
expect
(
getScrollOffset
(
tester
),
200
);
});
}
// 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