diff --git a/packages/flutter/lib/src/foundation/change_notifier.dart b/packages/flutter/lib/src/foundation/change_notifier.dart index 485be0febf..f79fb7b2da 100644 --- a/packages/flutter/lib/src/foundation/change_notifier.dart +++ b/packages/flutter/lib/src/foundation/change_notifier.dart @@ -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)); diff --git a/packages/flutter/lib/src/widgets/automatic_keep_alive.dart b/packages/flutter/lib/src/widgets/automatic_keep_alive.dart index 70da4a6b1b..06892cacb2 100644 --- a/packages/flutter/lib/src/widgets/automatic_keep_alive.dart +++ b/packages/flutter/lib/src/widgets/automatic_keep_alive.dart @@ -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 on State { void _releaseKeepAlive() { // Dispose and release do not imply each other. - _keepAliveHandle!.release(); _keepAliveHandle!.dispose(); _keepAliveHandle = null; }