@@ -11,26 +11,64 @@ import 'package:flutter_staggered_grid_view/src/widgets/staggered_tile.dart';
1111/// A base class for sliver that have multiple variable size box children.
1212///
1313/// Helps subclasses build their children lazily using a [SliverVariableSizeChildDelegate] .
14- abstract class SliverVariableSizeBoxAdaptorWidget extends SliverMultiKeepAliveBoxAdaptorWidget {
14+ abstract class SliverVariableSizeBoxAdaptorWidget extends SliverWithKeepAliveWidget {
1515 /// Initializes fields for subclasses.
1616 const SliverVariableSizeBoxAdaptorWidget ({
1717 Key key,
18- @required SliverChildDelegate delegate,
19- }) : super (key: key, delegate : delegate);
18+ @required this .delegate,
19+ }) : super (key: key);
20+
21+ /// The delegate that provides the children for this widget.
22+ ///
23+ /// The children are constructed lazily using this widget to avoid creating
24+ /// more children than are visible through the [Viewport] .
25+ ///
26+ /// See also:
27+ ///
28+ /// * [SliverChildBuilderDelegate] and [SliverChildListDelegate] , which are
29+ /// commonly used subclasses of [SliverChildDelegate] that use a builder
30+ /// callback and an explicit child list, respectively.
31+ final SliverChildDelegate delegate;
2032
2133 @override
2234 SliverVariableSizeBoxAdaptorElement createElement () =>
2335 new SliverVariableSizeBoxAdaptorElement (this );
2436
2537 @override
2638 RenderSliverVariableSizeBoxAdaptor createRenderObject (BuildContext context);
39+
40+ /// Returns an estimate of the max scroll extent for all the children.
41+ ///
42+ /// Subclasses should override this function if they have additional
43+ /// information about their max scroll extent.
44+ ///
45+ /// This is used by [SliverMultiBoxAdaptorElement] to implement part of the
46+ /// [RenderSliverBoxChildManager] API.
47+ ///
48+ /// The default implementation defers to [delegate] via its
49+ /// [SliverChildDelegate.estimateMaxScrollOffset] method.
50+ double estimateMaxScrollOffset (
51+ SliverConstraints constraints,
52+ int firstIndex,
53+ int lastIndex,
54+ double leadingScrollOffset,
55+ double trailingScrollOffset,
56+ ) {
57+ assert (lastIndex >= firstIndex);
58+ return delegate.estimateMaxScrollOffset (
59+ firstIndex,
60+ lastIndex,
61+ leadingScrollOffset,
62+ trailingScrollOffset,
63+ );
64+ }
2765}
2866
2967/// An element that lazily builds children for a [SliverVariableSizeBoxAdaptorWidget] .
3068///
3169/// Implements [RenderSliverVariableSizeBoxChildManager] , which lets this element manage
3270/// the children of subclasses of [RenderSliverVariableSizeBoxAdaptor] .
33- class SliverVariableSizeBoxAdaptorElement extends SliverMultiKeepAliveBoxAdaptorElement
71+ class SliverVariableSizeBoxAdaptorElement extends RenderObjectElement
3472 implements RenderSliverVariableSizeBoxChildManager {
3573 /// Creates an element that lazily builds children for the given widget.
3674 SliverVariableSizeBoxAdaptorElement (SliverVariableSizeBoxAdaptorWidget widget)
0 commit comments