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
457e7b23
Unverified
Commit
457e7b23
authored
Sep 01, 2018
by
xster
Committed by
GitHub
Sep 01, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix FixedExtentScrollController.animateToItem (#20618)
parent
4aaa5dfe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
5 deletions
+42
-5
list_wheel_scroll_view.dart
packages/flutter/lib/src/widgets/list_wheel_scroll_view.dart
+5
-5
list_wheel_scroll_view_test.dart
...ges/flutter/test/widgets/list_wheel_scroll_view_test.dart
+37
-0
No files found.
packages/flutter/lib/src/widgets/list_wheel_scroll_view.dart
View file @
457e7b23
...
...
@@ -250,15 +250,15 @@ class FixedExtentScrollController extends ScrollController {
/// The returned [Future] resolves when the animation completes.
///
/// The `duration` and `curve` arguments must not be null.
Future
<
Null
>
animateToItem
(
int
itemIndex
,
{
Future
<
void
>
animateToItem
(
int
itemIndex
,
{
@required
Duration
duration
,
@required
Curve
curve
,
})
{
})
async
{
if
(!
hasClients
)
{
return
new
Future
<
Null
>.
value
();
return
new
Future
<
void
>.
value
();
}
final
List
<
Future
<
Null
>>
futures
=
<
Future
<
Null
>>[];
final
List
<
Future
<
void
>>
futures
=
<
Future
<
void
>>[];
for
(
_FixedExtentScrollPosition
position
in
positions
)
{
futures
.
add
(
position
.
animateTo
(
itemIndex
*
position
.
itemExtent
,
...
...
@@ -266,7 +266,7 @@ class FixedExtentScrollController extends ScrollController {
curve:
curve
,
));
}
return
Future
.
wait
(
futures
);
return
await
Future
.
wait
(
futures
);
}
/// Changes which item index is centered in the controlled scroll view.
...
...
packages/flutter/test/widgets/list_wheel_scroll_view_test.dart
View file @
457e7b23
...
...
@@ -922,6 +922,43 @@ void main() {
expect
(
controller
.
selectedItem
,
0
);
});
testWidgets
(
'controller animateToItem'
,
(
WidgetTester
tester
)
async
{
final
FixedExtentScrollController
controller
=
new
FixedExtentScrollController
(
initialItem:
10
);
final
List
<
int
>
paintedChildren
=
<
int
>[];
await
tester
.
pumpWidget
(
new
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
new
ListWheelScrollView
(
controller:
controller
,
itemExtent:
100.0
,
children:
new
List
<
Widget
>.
generate
(
100
,
(
int
index
)
{
return
new
CustomPaint
(
painter:
new
TestCallbackPainter
(
onPaint:
()
{
paintedChildren
.
add
(
index
);
}),
);
}),
),
),
);
// Screen is 600px tall. Item 10 is in the center and each item is 100px tall.
expect
(
paintedChildren
,
<
int
>[
7
,
8
,
9
,
10
,
11
,
12
,
13
]);
paintedChildren
.
clear
();
controller
.
animateToItem
(
0
,
duration:
const
Duration
(
seconds:
1
),
curve:
Curves
.
linear
,
);
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
paintedChildren
,
<
int
>[
0
,
1
,
2
,
3
]);
expect
(
controller
.
selectedItem
,
0
);
});
testWidgets
(
'onSelectedItemChanged and controller are in sync'
,
(
WidgetTester
tester
)
async
{
final
List
<
int
>
selectedItems
=
<
int
>[];
final
FixedExtentScrollController
controller
=
new
FixedExtentScrollController
(
initialItem:
10
);
...
...
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