@@ -16,6 +16,71 @@ import 'viewport_offset.dart';
16
16
// CORE TYPES FOR SLIVERS
17
17
// The RenderSliver base class and its helper types.
18
18
19
+ /// Called to get the item extent by the index of item.
20
+ ///
21
+ /// Used by [ListView.itemExtentBuilder] and [SliverVariedExtentList.itemExtentBuilder] .
22
+ typedef ItemExtentBuilder = double Function (int index, SliverLayoutDimensions dimensions);
23
+
24
+ /// Relates the dimensions of the [RenderSliver] during layout.
25
+ ///
26
+ /// Used by [ListView.itemExtentBuilder] and [SliverVariedExtentList.itemExtentBuilder] .
27
+ @immutable
28
+ class SliverLayoutDimensions {
29
+ /// Constructs a [SliverLayoutDimensions] with the specified parameters.
30
+ const SliverLayoutDimensions ({
31
+ required this .scrollOffset,
32
+ required this .precedingScrollExtent,
33
+ required this .viewportMainAxisExtent,
34
+ required this .crossAxisExtent
35
+ });
36
+
37
+ /// {@macro flutter.rendering.SliverConstraints.scrollOffset}
38
+ final double scrollOffset;
39
+
40
+ /// {@macro flutter.rendering.SliverConstraints.precedingScrollExtent}
41
+ final double precedingScrollExtent;
42
+
43
+ /// The number of pixels the viewport can display in the main axis.
44
+ ///
45
+ /// For a vertical list, this is the height of the viewport.
46
+ final double viewportMainAxisExtent;
47
+
48
+ /// The number of pixels in the cross-axis.
49
+ ///
50
+ /// For a vertical list, this is the width of the sliver.
51
+ final double crossAxisExtent;
52
+
53
+ @override
54
+ bool operator == (Object other) {
55
+ if (identical (this , other)) {
56
+ return true ;
57
+ }
58
+ if (other is ! SliverLayoutDimensions ) {
59
+ return false ;
60
+ }
61
+ return other.scrollOffset == scrollOffset &&
62
+ other.precedingScrollExtent == precedingScrollExtent &&
63
+ other.viewportMainAxisExtent == viewportMainAxisExtent &&
64
+ other.crossAxisExtent == crossAxisExtent;
65
+ }
66
+
67
+ @override
68
+ String toString () {
69
+ return 'scrollOffset: $scrollOffset '
70
+ ' precedingScrollExtent: $precedingScrollExtent '
71
+ ' viewportMainAxisExtent: $viewportMainAxisExtent '
72
+ ' crossAxisExtent: $crossAxisExtent ' ;
73
+ }
74
+
75
+ @override
76
+ int get hashCode => Object .hash (
77
+ scrollOffset,
78
+ precedingScrollExtent,
79
+ viewportMainAxisExtent,
80
+ viewportMainAxisExtent
81
+ );
82
+ }
83
+
19
84
/// The direction in which a sliver's contents are ordered, relative to the
20
85
/// scroll offset axis.
21
86
///
@@ -224,12 +289,13 @@ class SliverConstraints extends Constraints {
224
289
/// {@macro flutter.rendering.ScrollDirection.sample}
225
290
final ScrollDirection userScrollDirection;
226
291
292
+ /// {@template flutter.rendering.SliverConstraints.scrollOffset}
227
293
/// The scroll offset, in this sliver's coordinate system, that corresponds to
228
294
/// the earliest visible part of this sliver in the [AxisDirection] if
229
- /// [growthDirection] is [GrowthDirection.forward] or in the opposite
230
- /// [AxisDirection] direction if [growthDirection] is [GrowthDirection.reverse] .
295
+ /// [SliverConstraints. growthDirection] is [GrowthDirection.forward] or in the opposite
296
+ /// [AxisDirection] direction if [SliverConstraints. growthDirection] is [GrowthDirection.reverse] .
231
297
///
232
- /// For example, if [AxisDirection] is [AxisDirection.down] and [growthDirection]
298
+ /// For example, if [AxisDirection] is [AxisDirection.down] and [SliverConstraints. growthDirection]
233
299
/// is [GrowthDirection.forward] , then scroll offset is the amount the top of
234
300
/// the sliver has been scrolled past the top of the viewport.
235
301
///
@@ -240,7 +306,7 @@ class SliverConstraints extends Constraints {
240
306
///
241
307
/// For slivers whose top is not past the top of the viewport, the
242
308
/// [scrollOffset] is `0` when [AxisDirection] is [AxisDirection.down] and
243
- /// [growthDirection] is [GrowthDirection.forward] . The set of slivers with
309
+ /// [SliverConstraints. growthDirection] is [GrowthDirection.forward] . The set of slivers with
244
310
/// [scrollOffset] `0` includes all the slivers that are below the bottom of the
245
311
/// viewport.
246
312
///
@@ -249,9 +315,11 @@ class SliverConstraints extends Constraints {
249
315
/// partially 'protrude in' from the bottom of the viewport.
250
316
///
251
317
/// Whether this corresponds to the beginning or the end of the sliver's
252
- /// contents depends on the [growthDirection] .
318
+ /// contents depends on the [SliverConstraints.growthDirection] .
319
+ /// {@endtemplate}
253
320
final double scrollOffset;
254
321
322
+ /// {@template flutter.rendering.SliverConstraints.precedingScrollExtent}
255
323
/// The scroll distance that has been consumed by all [RenderSliver] s that
256
324
/// came before this [RenderSliver] .
257
325
///
@@ -273,6 +341,7 @@ class SliverConstraints extends Constraints {
273
341
/// content forever without reaching the end. For any [RenderSliver] s that
274
342
/// appear after the infinite [RenderSliver] , the [precedingScrollExtent] will
275
343
/// be [double.infinity] .
344
+ /// {@endtemplate}
276
345
final double precedingScrollExtent;
277
346
278
347
/// The number of pixels from where the pixels corresponding to the
0 commit comments