@@ -27,13 +27,23 @@ import 'sliver.dart';
27
27
///
28
28
/// To send these notifications, consider using [AutomaticKeepAliveClientMixin] .
29
29
///
30
+ /// The [SliverChildBuilderDelegate] and [SliverChildListDelegate] delegates,
31
+ /// used with [SliverList] and [SliverGrid] , as well as the scroll view
32
+ /// counterparts [ListView] and [GridView] , have an `addAutomaticKeepAlives`
33
+ /// feature, which is enabled by default. This feature inserts
34
+ /// [AutomaticKeepAlive] widgets around each child, which in turn configure
35
+ /// [KeepAlive] widgets in response to [KeepAliveNotification] s.
36
+ ///
37
+ /// The same `addAutomaticKeepAlives` feature is supported by
38
+ /// [TwoDimensionalChildBuilderDelegate] and [TwoDimensionalChildListDelegate] .
39
+ ///
30
40
/// {@tool dartpad}
31
41
/// This sample demonstrates how to use the [AutomaticKeepAlive] widget in
32
42
/// combination with the [AutomaticKeepAliveClientMixin] to selectively preserve
33
43
/// the state of individual items in a scrollable list.
34
44
///
35
45
/// Normally, widgets in a lazily built list like [ListView.builder] are
36
- /// disposed of when they leave the visible area to save resources . This means
46
+ /// disposed of when they leave the visible area to maintain performance . This means
37
47
/// that any state inside a [StatefulWidget] would be lost unless explicitly
38
48
/// preserved.
39
49
///
@@ -50,6 +60,13 @@ import 'sliver.dart';
50
60
/// ** See code in examples/api/lib/widgets/keep_alive/automatic_keep_alive.0.dart **
51
61
/// {@end-tool}
52
62
///
63
+ /// See also:
64
+ ///
65
+ /// * [AutomaticKeepAliveClientMixin] , which is a mixin with convenience
66
+ /// methods for clients of [AutomaticKeepAlive]. Used with [State]
67
+ /// subclasses.
68
+ /// * [KeepAlive] which marks a child as needing to stay alive even when it's
69
+ /// in a lazy list that would otherwise remove it.
53
70
class AutomaticKeepAlive extends StatefulWidget {
54
71
/// Creates a widget that listens to [KeepAliveNotification] s and maintains a
55
72
/// [KeepAlive] widget appropriately.
@@ -354,8 +371,19 @@ class KeepAliveHandle extends ChangeNotifier {
354
371
}
355
372
}
356
373
357
- /// A mixin with convenience methods for clients of [AutomaticKeepAlive] . Used
358
- /// with [State] subclasses.
374
+ /// A mixin with convenience methods for clients of [AutomaticKeepAlive] . It is used
375
+ /// with [State] subclasses to manage keep-alive behavior in lazily built lists.
376
+ ///
377
+ /// This mixin simplifies interaction with [AutomaticKeepAlive] by automatically
378
+ /// sending [KeepAliveNotification] s when necessary. Subclasses must implement
379
+ /// [wantKeepAlive] to indicate whether the widget should be kept alive and call
380
+ /// [updateKeepAlive] whenever its value changes.
381
+ ///
382
+ /// The mixin internally manages a [KeepAliveHandle] , which is used to notify
383
+ /// the nearest [AutomaticKeepAlive] ancestor of changes in keep-alive
384
+ /// requirements. [AutomaticKeepAlive] listens for [KeepAliveNotification] s sent
385
+ /// by this mixin and dynamically wraps the subtree in a [KeepAlive] widget to
386
+ /// preserve its state when it is no longer visible in the viewport.
359
387
///
360
388
/// Subclasses must implement [wantKeepAlive] , and their [build] methods must
361
389
/// call `super.build` (though the return value should be ignored).
@@ -366,9 +394,20 @@ class KeepAliveHandle extends ChangeNotifier {
366
394
/// The type argument `T` is the type of the [StatefulWidget] subclass of the
367
395
/// [State] into which this class is being mixed.
368
396
///
397
+ /// The [SliverChildBuilderDelegate] and [SliverChildListDelegate] delegates,
398
+ /// used with [SliverList] and [SliverGrid] , as well as the scroll view
399
+ /// counterparts [ListView] and [GridView] , have an `addAutomaticKeepAlives`
400
+ /// feature, which is enabled by default. This feature inserts
401
+ /// [AutomaticKeepAlive] widgets around each child, which in turn configure
402
+ /// [KeepAlive] widgets in response to [KeepAliveNotification] s.
403
+ ///
404
+ /// The same `addAutomaticKeepAlives` feature is supported by
405
+ /// [TwoDimensionalChildBuilderDelegate] and [TwoDimensionalChildListDelegate] .
406
+ ///
369
407
/// {@tool dartpad}
370
- /// This example demonstrates how to use the [AutomaticKeepAliveClientMixin]
371
- /// to keep the state of a widget alive even when it is scrolled out of view.
408
+ /// This example demonstrates how to use the
409
+ /// [AutomaticKeepAliveClientMixin] to keep the state of a widget alive even
410
+ /// when it is scrolled out of view.
372
411
///
373
412
/// ** See code in examples/api/lib/widgets/keep_alive/automatic_keep_alive_client_mixin.0.dart **
374
413
/// {@end-tool}
@@ -377,6 +416,8 @@ class KeepAliveHandle extends ChangeNotifier {
377
416
///
378
417
/// * [AutomaticKeepAlive] , which listens to messages from this mixin.
379
418
/// * [KeepAliveNotification] , the notifications sent by this mixin.
419
+ /// * [KeepAlive] which marks a child as needing to stay alive even when it's
420
+ /// in a lazy list that would otherwise remove it.
380
421
@optionalTypeArgs
381
422
mixin AutomaticKeepAliveClientMixin <T extends StatefulWidget > on State <T > {
382
423
KeepAliveHandle ? _keepAliveHandle;
0 commit comments