Update docs on ChangeNotifier.dispose and KeepAliveHandle.release (#108384)
This commit is contained in:
@@ -297,6 +297,10 @@ class ChangeNotifier implements Listenable {
|
||||
/// [addListener] will throw after the object is disposed).
|
||||
///
|
||||
/// This method should only be called by the object's owner.
|
||||
///
|
||||
/// This method does not notify listeners, and clears the listener list once
|
||||
/// it is called. Consumers of this class must decide on whether to notify
|
||||
/// listeners or not immediately before disposal.
|
||||
@mustCallSuper
|
||||
void dispose() {
|
||||
assert(ChangeNotifier.debugAssertNotDisposed(this));
|
||||
|
||||
@@ -321,9 +321,22 @@ class KeepAliveNotification extends Notification {
|
||||
class KeepAliveHandle extends ChangeNotifier {
|
||||
/// Trigger the listeners to indicate that the widget
|
||||
/// no longer needs to be kept alive.
|
||||
///
|
||||
/// This method does not call [dispose]. When the handle is not needed
|
||||
/// anymore, it must be [dispose]d regardless of whether notifying listeners.
|
||||
@Deprecated(
|
||||
'Use dispose instead. '
|
||||
'This feature was deprecated after v3.3.0-0.0.pre.',
|
||||
)
|
||||
void release() {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
notifyListeners();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// A mixin with convenience methods for clients of [AutomaticKeepAlive]. Used
|
||||
@@ -354,7 +367,6 @@ mixin AutomaticKeepAliveClientMixin<T extends StatefulWidget> on State<T> {
|
||||
|
||||
void _releaseKeepAlive() {
|
||||
// Dispose and release do not imply each other.
|
||||
_keepAliveHandle!.release();
|
||||
_keepAliveHandle!.dispose();
|
||||
_keepAliveHandle = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user