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
fcfcfd56
Commit
fcfcfd56
authored
Dec 10, 2015
by
Hans Muller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support an empty PageableList
parent
a9f0044e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
14 deletions
+53
-14
homogeneous_viewport.dart
packages/flutter/lib/src/widgets/homogeneous_viewport.dart
+4
-4
pageable_list.dart
packages/flutter/lib/src/widgets/pageable_list.dart
+7
-7
pageable_list_test.dart
packages/unit/test/widget/pageable_list_test.dart
+42
-3
No files found.
packages/flutter/lib/src/widgets/homogeneous_viewport.dart
View file @
fcfcfd56
...
...
@@ -256,7 +256,6 @@ class _HomogeneousPageViewportElement extends _ViewportBaseElement<HomogeneousPa
// doing our own layout.)
BuildableElement
.
lockState
(()
{
double
itemExtent
=
widget
.
direction
==
ScrollDirection
.
vertical
?
constraints
.
maxHeight
:
constraints
.
maxWidth
;
double
contentExtent
=
itemExtent
*
widget
.
itemCount
;
double
offset
;
if
(
widget
.
startOffset
<=
0.0
&&
!
widget
.
itemsWrap
)
{
_layoutFirstIndex
=
0
;
...
...
@@ -265,9 +264,10 @@ class _HomogeneousPageViewportElement extends _ViewportBaseElement<HomogeneousPa
_layoutFirstIndex
=
widget
.
startOffset
.
floor
();
offset
=
-((
widget
.
startOffset
*
itemExtent
)
%
itemExtent
);
}
if
(
itemExtent
<
double
.
INFINITY
)
{
_layoutItemCount
=
((
contentExtent
-
offset
)
/
contentExtent
).
ceil
();
if
(
widget
.
itemCount
!=
null
&&
!
widget
.
itemsWrap
)
if
(
itemExtent
<
double
.
INFINITY
&&
widget
.
itemCount
!=
null
)
{
final
double
contentExtent
=
itemExtent
*
widget
.
itemCount
;
_layoutItemCount
=
contentExtent
==
0.0
?
0
:
((
contentExtent
-
offset
)
/
contentExtent
).
ceil
();
if
(!
widget
.
itemsWrap
)
_layoutItemCount
=
math
.
min
(
_layoutItemCount
,
widget
.
itemCount
-
_layoutFirstIndex
);
}
else
{
assert
(()
{
...
...
packages/flutter/lib/src/widgets/pageable_list.dart
View file @
fcfcfd56
...
...
@@ -148,15 +148,15 @@ class PageableListState<T, Config extends PageableList<T>> extends ScrollableSta
bool
get
snapScrollOffsetChanges
=>
config
.
itemsSnapAlignment
==
ItemsSnapAlignment
.
item
;
double
snapScrollOffset
(
double
newScrollOffset
)
{
double
previousItemOffset
=
newScrollOffset
.
floorToDouble
();
double
nextItemOffset
=
newScrollOffset
.
ceilToDouble
();
final
double
previousItemOffset
=
newScrollOffset
.
floorToDouble
();
final
double
nextItemOffset
=
newScrollOffset
.
ceilToDouble
();
return
(
newScrollOffset
-
previousItemOffset
<
0.5
?
previousItemOffset
:
nextItemOffset
)
.
clamp
(
scrollBehavior
.
minScrollOffset
,
scrollBehavior
.
maxScrollOffset
);
}
Future
_flingToAdjacentItem
(
Offset
velocity
)
{
double
scrollVelocity
=
scrollDirectionVelocity
(
velocity
);
double
newScrollOffset
=
snapScrollOffset
(
scrollOffset
+
scrollVelocity
.
sign
)
final
double
scrollVelocity
=
scrollDirectionVelocity
(
velocity
);
final
double
newScrollOffset
=
snapScrollOffset
(
scrollOffset
+
scrollVelocity
.
sign
)
.
clamp
(
snapScrollOffset
(
scrollOffset
-
0.5
),
snapScrollOffset
(
scrollOffset
+
0.5
));
return
scrollTo
(
newScrollOffset
,
duration:
config
.
duration
,
curve:
config
.
curve
)
.
then
(
_notifyPageChanged
);
...
...
@@ -177,9 +177,9 @@ class PageableListState<T, Config extends PageableList<T>> extends ScrollableSta
}
List
<
Widget
>
buildItems
(
BuildContext
context
,
int
start
,
int
count
)
{
List
<
Widget
>
result
=
new
List
<
Widget
>();
int
begin
=
config
.
itemsWrap
?
start
:
math
.
max
(
0
,
start
);
int
end
=
config
.
itemsWrap
?
begin
+
count
:
math
.
min
(
begin
+
count
,
config
.
items
.
length
);
final
List
<
Widget
>
result
=
new
List
<
Widget
>();
final
int
begin
=
config
.
itemsWrap
?
start
:
math
.
max
(
0
,
start
);
final
int
end
=
config
.
itemsWrap
?
begin
+
count
:
math
.
min
(
begin
+
count
,
itemCount
);
for
(
int
i
=
begin
;
i
<
end
;
++
i
)
result
.
add
(
config
.
itemBuilder
(
context
,
config
.
items
[
i
%
itemCount
],
i
));
assert
(
result
.
every
((
Widget
item
)
=>
item
.
key
!=
null
));
...
...
packages/unit/test/widget/pageable_list_test.dart
View file @
fcfcfd56
...
...
@@ -7,7 +7,7 @@ import 'package:flutter/widgets.dart';
import
'package:test/test.dart'
;
const
Size
pageSize
=
const
Size
(
800.0
,
600.0
);
const
List
<
int
>
p
ages
=
const
<
int
>[
0
,
1
,
2
,
3
,
4
,
5
];
const
List
<
int
>
defaultP
ages
=
const
<
int
>[
0
,
1
,
2
,
3
,
4
,
5
];
int
currentPage
=
null
;
bool
itemsWrap
=
false
;
...
...
@@ -20,7 +20,7 @@ Widget buildPage(BuildContext context, int page, int index) {
);
}
Widget
buildFrame
(
)
{
Widget
buildFrame
(
{
List
<
int
>
pages:
defaultPages
}
)
{
// The test framework forces the frame (and so the PageableList)
// to be 800x600. The pageSize constant reflects this.
return
new
PageableList
<
int
>(
...
...
@@ -66,7 +66,6 @@ void main() {
test
(
'PageableList with itemsWrap: true'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Container
());
currentPage
=
null
;
itemsWrap
=
true
;
tester
.
pumpWidget
(
buildFrame
());
...
...
@@ -79,4 +78,44 @@ void main() {
expect
(
currentPage
,
equals
(
5
));
});
});
test
(
'PageableList with two items'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
currentPage
=
null
;
itemsWrap
=
true
;
tester
.
pumpWidget
(
buildFrame
(
pages:
<
int
>[
0
,
1
]));
expect
(
currentPage
,
isNull
);
pageLeft
(
tester
);
expect
(
currentPage
,
equals
(
1
));
pageRight
(
tester
);
expect
(
currentPage
,
equals
(
0
));
pageRight
(
tester
);
expect
(
currentPage
,
equals
(
1
));
});
});
test
(
'PageableList with one item'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
currentPage
=
null
;
itemsWrap
=
true
;
tester
.
pumpWidget
(
buildFrame
(
pages:
<
int
>[
0
]));
expect
(
currentPage
,
isNull
);
pageLeft
(
tester
);
expect
(
currentPage
,
equals
(
0
));
pageRight
(
tester
);
expect
(
currentPage
,
equals
(
0
));
pageRight
(
tester
);
expect
(
currentPage
,
equals
(
0
));
});
});
test
(
'PageableList with no items'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
currentPage
=
null
;
itemsWrap
=
true
;
tester
.
pumpWidget
(
buildFrame
(
pages:
null
));
expect
(
currentPage
,
isNull
);
});
});
}
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