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
a3ecdc30
Commit
a3ecdc30
authored
Sep 29, 2015
by
Hans Muller
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1400 from HansMuller/land_snap_scrolling_unit_test
Land snap_scrolling_test.dart
parents
6bd9229d
9b659089
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
0 deletions
+87
-0
snap_scrolling_test.dart
packages/unit/test/widget/snap_scrolling_test.dart
+87
-0
No files found.
packages/unit/test/widget/snap_scrolling_test.dart
0 → 100644
View file @
a3ecdc30
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:quiver/testing/async.dart'
;
import
'package:sky/src/fn3.dart'
;
import
'package:test/test.dart'
;
import
'../fn3/widget_tester.dart'
;
const
double
itemExtent
=
200.0
;
ScrollDirection
scrollDirection
=
ScrollDirection
.
vertical
;
GlobalKey
scrollableListKey
;
Widget
buildItem
(
BuildContext
context
,
int
item
)
{
return
new
Container
(
key:
new
ValueKey
<
int
>(
item
),
width:
itemExtent
,
height:
itemExtent
,
child:
new
Text
(
item
.
toString
())
);
}
double
snapOffsetCallback
(
double
offset
)
{
return
(
offset
/
itemExtent
).
floor
()
*
itemExtent
;
}
Widget
buildScrollableList
(
)
{
scrollableListKey
=
new
GlobalKey
();
return
new
Container
(
height:
itemExtent
*
2.0
,
child:
new
ScrollableList
<
int
>(
key:
scrollableListKey
,
snapOffsetCallback:
snapOffsetCallback
,
scrollDirection:
scrollDirection
,
items:
[
0
,
1
,
2
,
3
,
4
,
5
,
7
,
8
,
9
],
itemBuilder:
buildItem
,
itemExtent:
itemExtent
)
);
}
ScrollableState
get
scrollableState
=>
scrollableListKey
.
currentState
;
double
get
scrollOffset
=>
scrollableState
.
scrollOffset
;
void
set
scrollOffset
(
double
value
)
{
scrollableState
.
scrollTo
(
value
);
}
void
fling
(
double
velocity
)
{
Offset
velocityOffset
=
scrollDirection
==
ScrollDirection
.
vertical
?
new
Offset
(
0.0
,
velocity
)
:
new
Offset
(
velocity
,
0.0
);
scrollableState
.
fling
(
velocityOffset
);
}
void
main
(
)
{
test
(
'ScrollableList snap scrolling, fling(-800)'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
new
Center
(
child:
buildScrollableList
()));
expect
(
scrollOffset
,
0.0
);
new
FakeAsync
().
run
((
async
)
{
fling
(-
800.0
);
tester
.
pumpFrameWithoutChange
();
// Start the scheduler at 0.0
tester
.
pumpFrameWithoutChange
(
1000.0
);
async
.
elapse
(
new
Duration
(
seconds:
1
));
expect
(
scrollOffset
,
closeTo
(
200.0
,
1.0
));
});
});
test
(
'ScrollableList snap scrolling, fling(-2000)'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
new
Center
(
child:
buildScrollableList
()));
expect
(
scrollOffset
,
0.0
);
new
FakeAsync
().
run
((
async
)
{
fling
(-
2000.0
);
tester
.
pumpFrameWithoutChange
();
// Start the scheduler at 0.0
tester
.
pumpFrameWithoutChange
(
1000.0
);
async
.
elapse
(
new
Duration
(
seconds:
1
));
expect
(
scrollOffset
,
closeTo
(
400.0
,
1.0
));
});
});
}
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