Update docs on ChangeNotifier.dispose and KeepAliveHandle.release (#108384)

This commit is contained in:
Dan Field
2022-07-26 15:09:05 -07:00
committed by GitHub
parent f1ebd28883
commit 201be6bdf5
2 changed files with 17 additions and 1 deletions

View File

@@ -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));

View File

@@ -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;
}