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
fecc4e65
Commit
fecc4e65
authored
Mar 13, 2017
by
Adam Barth
Committed by
GitHub
Mar 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Docs for RenderSliverFixedExtentList (#8733)
Also, some renames for more accuracy.
parent
8742fb09
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
13 deletions
+109
-13
sliver_fixed_extent_list.dart
...s/flutter/lib/src/rendering/sliver_fixed_extent_list.dart
+106
-10
sliver_grid.dart
packages/flutter/lib/src/rendering/sliver_grid.dart
+1
-1
sliver_multi_box_adaptor.dart
...s/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart
+2
-2
No files found.
packages/flutter/lib/src/rendering/sliver_fixed_extent_list.dart
View file @
fecc4e65
...
...
@@ -10,7 +10,33 @@ import 'box.dart';
import
'sliver.dart'
;
import
'sliver_multi_box_adaptor.dart'
;
/// A sliver that contains multiple box children that have the same extent in
/// the main axis.
///
/// [RenderSliverFixedExtentBoxAdaptor] places its children in a linear array
/// along the main axis. Each child is forced to have the [itemExtent] in the
/// main axis and the [SliverConstraints.crossAxisExtent] in the cross axis.
///
/// Subclasses should override [itemExtent] to control the size of the children
/// in the main axis. For a concrete subclass with a configurable [itemExtent],
/// see [RenderSliverFixedExtentList].
///
/// [RenderSliverFixedExtentBoxAdaptor] is more efficient than
/// [RenderSliverList] because [RenderSliverFixedExtentBoxAdaptor] does not need
/// to perform layout on its children to obtain their extent in the main axis.
///
/// See also:
///
/// * [RenderSliverFixedExtentList], which has a configurable [itemExtent].
/// * [RenderSliverFill], which determines the [itemExtent] based on
/// [SliverConstraints.viewportMainAxisExtent].
/// * [RenderSliverList], which does not require its children to have the same
/// extent in the main axis.
abstract
class
RenderSliverFixedExtentBoxAdaptor
extends
RenderSliverMultiBoxAdaptor
{
/// Creates a sliver that contains multiple box children that have the same
/// extent in the main axis.
///
/// The [childManager] argument must not be null.
RenderSliverFixedExtentBoxAdaptor
({
@required
RenderSliverBoxChildManager
childManager
,
})
:
super
(
childManager:
childManager
);
...
...
@@ -18,19 +44,47 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda
/// The main-axis extent of each item.
double
get
itemExtent
;
/// The layout offset for the child with the given index.
///
/// This function is given the [itemExtent] as an argument to avoid
/// recomputing [itemExtent] repeatedly during layout.
///
/// By default, places the children in order, without gaps, starting from
/// layout offset zero.
@protected
double
indexToScrollOffset
(
double
itemExtent
,
int
index
)
=>
itemExtent
*
index
;
double
indexToLayoutOffset
(
double
itemExtent
,
int
index
)
=>
itemExtent
*
index
;
/// The minimum child index that is visible at the given scroll offset.
///
/// This function is given the [itemExtent] as an argument to avoid
/// recomputing [itemExtent] repeatedly during layout.
///
/// By default, returns a value consistent with the children being placed in
/// order, without gaps, starting from layout offset zero.
@protected
int
getMinChildIndexForScrollOffset
(
double
scrollOffset
,
double
itemExtent
)
{
return
itemExtent
>
0.0
?
math
.
max
(
0
,
scrollOffset
~/
itemExtent
)
:
0
;
}
/// The maximum child index that is visible at the given scroll offset.
///
/// This function is given the [itemExtent] as an argument to avoid
/// recomputing [itemExtent] repeatedly during layout.
///
/// By default, returns a value consistent with the children being placed in
/// order, without gaps, starting from layout offset zero.
@protected
int
getMaxChildIndexForScrollOffset
(
double
scrollOffset
,
double
itemExtent
)
{
return
itemExtent
>
0.0
?
math
.
max
(
0
,
(
scrollOffset
/
itemExtent
).
ceil
()
-
1
)
:
0
;
}
/// Called to estimate the total scrollable extents of this object.
///
/// Must return the total distance from the start of the child with the
/// earliest possible index to the end of the child with the last possible
/// index.
///
/// By default, defers to [RenderSliverBoxChildManager.estimateMaxScrollOffset].
@protected
double
estimateMaxScrollOffset
(
SliverConstraints
constraints
,
{
int
firstIndex
,
...
...
@@ -78,7 +132,7 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda
}
if
(
firstChild
==
null
)
{
if
(!
addInitialChild
(
index:
firstIndex
,
scrollOffset:
indexToScroll
Offset
(
itemExtent
,
firstIndex
)))
{
if
(!
addInitialChild
(
index:
firstIndex
,
layoutOffset:
indexToLayout
Offset
(
itemExtent
,
firstIndex
)))
{
// There are no children.
geometry
=
SliverGeometry
.
zero
;
return
;
...
...
@@ -90,7 +144,7 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda
for
(
int
index
=
indexOf
(
firstChild
)
-
1
;
index
>=
firstIndex
;
--
index
)
{
final
RenderBox
child
=
insertAndLayoutLeadingChild
(
childConstraints
);
final
SliverMultiBoxAdaptorParentData
childParentData
=
child
.
parentData
;
childParentData
.
layoutOffset
=
indexTo
Scroll
Offset
(
itemExtent
,
index
);
childParentData
.
layoutOffset
=
indexTo
Layout
Offset
(
itemExtent
,
index
);
assert
(
childParentData
.
index
==
index
);
trailingChildWithLayout
??=
child
;
}
...
...
@@ -98,7 +152,7 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda
if
(
trailingChildWithLayout
==
null
)
{
firstChild
.
layout
(
childConstraints
);
final
SliverMultiBoxAdaptorParentData
childParentData
=
firstChild
.
parentData
;
childParentData
.
layoutOffset
=
indexTo
Scroll
Offset
(
itemExtent
,
firstIndex
);
childParentData
.
layoutOffset
=
indexTo
Layout
Offset
(
itemExtent
,
firstIndex
);
trailingChildWithLayout
=
firstChild
;
}
...
...
@@ -116,12 +170,12 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda
trailingChildWithLayout
=
child
;
assert
(
child
!=
null
);
final
SliverMultiBoxAdaptorParentData
childParentData
=
child
.
parentData
;
childParentData
.
layoutOffset
=
indexTo
Scroll
Offset
(
itemExtent
,
childParentData
.
index
);
childParentData
.
layoutOffset
=
indexTo
Layout
Offset
(
itemExtent
,
childParentData
.
index
);
}
final
int
lastIndex
=
indexOf
(
lastChild
);
final
double
leadingScrollOffset
=
indexTo
Scroll
Offset
(
itemExtent
,
firstIndex
);
final
double
trailingScrollOffset
=
indexTo
Scroll
Offset
(
itemExtent
,
lastIndex
+
1
);
final
double
leadingScrollOffset
=
indexTo
Layout
Offset
(
itemExtent
,
firstIndex
);
final
double
trailingScrollOffset
=
indexTo
Layout
Offset
(
itemExtent
,
lastIndex
+
1
);
assert
(
firstIndex
==
0
||
childScrollOffset
(
firstChild
)
<=
scrollOffset
);
assert
(
debugAssertChildListIsNonEmptyAndContiguous
());
...
...
@@ -154,7 +208,29 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda
}
}
/// A sliver that contains multiple box children that have a given extent in the
/// main axis.
///
/// [RenderSliverFixedExtentList] places its children in a linear array along
/// the main axis starting at offset zero and without gaps. Each child is forced
/// to have the [itemExtent] in the main axis and the
/// [SliverConstraints.crossAxisExtent] in the cross axis.
///
/// [RenderSliverFixedExtentList] is more efficient than [RenderSliverList]
/// because [RenderSliverFixedExtentList] does not need to perform layout on its
/// children to obtain their extent in the main axis.
///
/// See also:
///
/// * [RenderSliverFill], which determines the [itemExtent] based on
/// [SliverConstraints.viewportMainAxisExtent].
/// * [RenderSliverList], which does not require its children to have the same
/// extent in the main axis.
class
RenderSliverFixedExtentList
extends
RenderSliverFixedExtentBoxAdaptor
{
/// Creates a sliver that contains multiple box children that have a given
/// extent in the main axis.
///
/// The [childManager] argument must not be null.
RenderSliverFixedExtentList
({
@required
RenderSliverBoxChildManager
childManager
,
double
itemExtent
,
...
...
@@ -172,7 +248,22 @@ class RenderSliverFixedExtentList extends RenderSliverFixedExtentBoxAdaptor {
}
}
/// A sliver that contains a multiple box children that each fill the viewport.
///
/// [RenderSliverFill] places its children in a linear array along the main
/// axis. Each child is sized to fill the viewport, both in the main and cross
/// axis.
///
/// See also:
///
/// * [RenderSliverFixedExtentList], which has a configurable [itemExtent].
/// * [RenderSliverList], which does not require its children to have the same
/// extent in the main axis.
class
RenderSliverFill
extends
RenderSliverFixedExtentBoxAdaptor
{
/// Creates a sliver that contains a multiple box children that each fill the
/// viewport.
///
/// The [childManager] argument must not be null.
RenderSliverFill
({
@required
RenderSliverBoxChildManager
childManager
,
double
viewportFraction:
1.0
,
...
...
@@ -184,6 +275,11 @@ class RenderSliverFill extends RenderSliverFixedExtentBoxAdaptor {
@override
double
get
itemExtent
=>
constraints
.
viewportMainAxisExtent
*
viewportFraction
;
/// The fraction of the viewport that each child should fill in the main axis.
///
/// If this fraction is less than 1.0, more than one child will be visible at
/// once. If this fraction is greater than 1.0, each child will be larger than
/// the viewport in the main axis.
double
get
viewportFraction
=>
_viewportFraction
;
double
_viewportFraction
;
set
viewportFraction
(
double
value
)
{
...
...
@@ -197,8 +293,8 @@ class RenderSliverFill extends RenderSliverFixedExtentBoxAdaptor {
double
get
_padding
=>
(
1.0
-
viewportFraction
)
*
constraints
.
viewportMainAxisExtent
*
0.5
;
@override
double
indexTo
Scroll
Offset
(
double
itemExtent
,
int
index
)
{
return
_padding
+
super
.
indexTo
Scroll
Offset
(
itemExtent
,
index
);
double
indexTo
Layout
Offset
(
double
itemExtent
,
int
index
)
{
return
_padding
+
super
.
indexTo
Layout
Offset
(
itemExtent
,
index
);
}
@override
...
...
packages/flutter/lib/src/rendering/sliver_grid.dart
View file @
fecc4e65
...
...
@@ -473,7 +473,7 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {
if
(
firstChild
==
null
)
{
if
(!
addInitialChild
(
index:
firstIndex
,
scroll
Offset:
firstChildGridGeometry
.
scrollOffset
))
{
layout
Offset:
firstChildGridGeometry
.
scrollOffset
))
{
// There are no children.
geometry
=
SliverGeometry
.
zero
;
return
;
...
...
packages/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart
View file @
fecc4e65
...
...
@@ -162,7 +162,7 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
/// during the call to createChild. No child should be added during that call
/// either, except for the one that is created and returned by createChild.
@protected
bool
addInitialChild
({
int
index:
0
,
double
scroll
Offset:
0.0
})
{
bool
addInitialChild
({
int
index:
0
,
double
layout
Offset:
0.0
})
{
assert
(
_debugAssertChildListLocked
());
assert
(
firstChild
==
null
);
bool
result
;
...
...
@@ -173,7 +173,7 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
assert
(
firstChild
==
lastChild
);
assert
(
indexOf
(
firstChild
)
==
index
);
final
SliverMultiBoxAdaptorParentData
firstChildParentData
=
firstChild
.
parentData
;
firstChildParentData
.
layoutOffset
=
scroll
Offset
;
firstChildParentData
.
layoutOffset
=
layout
Offset
;
result
=
true
;
}
else
{
childManager
.
setDidUnderflow
(
true
);
...
...
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