Skip to content

Commit d8ca660

Browse files
committed
remove custom keep alive
1 parent d3487d0 commit d8ca660

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

lib/src/rendering/sliver_variable_size_box_adaptor.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,11 @@ class SliverVariableSizeBoxAdaptorParentData
159159
/// * [RenderSliverFixedExtentList], which places its children in a linear
160160
/// array with a fixed extent in the main axis.
161161
/// * [RenderSliverGrid], which places its children in arbitrary positions.
162-
abstract class RenderSliverVariableSizeBoxAdaptor extends RenderSliverMultiKeepAliveBoxAdaptor
162+
abstract class RenderSliverVariableSizeBoxAdaptor extends RenderSliver
163163
with
164164
TileContainerRenderObjectMixin<RenderBox,
165165
SliverVariableSizeBoxAdaptorParentData>,
166+
RenderSliverWithKeepAliveMixin,
166167
RenderSliverHelpers {
167168
/// Creates a sliver with multiple box children.
168169
///

lib/src/widgets/sliver.dart

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)