From 54bed9215572a903118fd38bd39ee40a16b16961 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Tue, 22 Oct 2024 14:51:02 +0200 Subject: [PATCH] Added AsyncNotifier.listenSelf fixes #3795 --- packages/flutter_riverpod/CHANGELOG.md | 4 ++++ packages/hooks_riverpod/CHANGELOG.md | 4 ++++ packages/riverpod/CHANGELOG.md | 4 ++++ packages/riverpod/lib/src/async_notifier.dart | 9 +++++++++ packages/riverpod/lib/src/notifier.dart | 2 ++ 5 files changed, 23 insertions(+) diff --git a/packages/flutter_riverpod/CHANGELOG.md b/packages/flutter_riverpod/CHANGELOG.md index e348612f1..74603d025 100644 --- a/packages/flutter_riverpod/CHANGELOG.md +++ b/packages/flutter_riverpod/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased 2.6.1 + +- Added `AsyncNotifier.listenSelf`. It was mistakenly absent from the 2.6.0 release + ## 2.6.0 - 2024-10-20 - Deprecated all `Ref` subclasses. Instead, use `Ref` itself. diff --git a/packages/hooks_riverpod/CHANGELOG.md b/packages/hooks_riverpod/CHANGELOG.md index 1b589a1c3..965f06a38 100644 --- a/packages/hooks_riverpod/CHANGELOG.md +++ b/packages/hooks_riverpod/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased 2.6.1 + +- Added `AsyncNotifier.listenSelf`. It was mistakenly absent from the 2.6.0 release + ## 2.6.0 - 2024-10-20 - Deprecated all `Ref` subclasses. Instead, use `Ref` itself. diff --git a/packages/riverpod/CHANGELOG.md b/packages/riverpod/CHANGELOG.md index 39ce114b3..359a19f9d 100644 --- a/packages/riverpod/CHANGELOG.md +++ b/packages/riverpod/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased 2.6.1 + +- Added `AsyncNotifier.listenSelf`. It was mistakenly absent from the 2.6.0 release + ## 2.6.0 - 2024-10-20 - Deprecated all `Ref` subclasses. Instead, use `Ref` itself. diff --git a/packages/riverpod/lib/src/async_notifier.dart b/packages/riverpod/lib/src/async_notifier.dart index 7de3d033d..f5174a3c6 100644 --- a/packages/riverpod/lib/src/async_notifier.dart +++ b/packages/riverpod/lib/src/async_notifier.dart @@ -33,6 +33,15 @@ abstract class AsyncNotifierBase { void _setElement(ProviderElementBase> element); + /// {@macro notifier.listen} + void listenSelf( + void Function(AsyncValue? previous, AsyncValue next) + listener, { + void Function(Object error, StackTrace stackTrace)? onError, + }) { + _element.listenSelf(listener, onError: onError); + } + /// The value currently exposed by this [AsyncNotifier]. /// /// Defaults to [AsyncLoading] inside the [AsyncNotifier.build] method. diff --git a/packages/riverpod/lib/src/notifier.dart b/packages/riverpod/lib/src/notifier.dart index f6431159c..c7043c372 100644 --- a/packages/riverpod/lib/src/notifier.dart +++ b/packages/riverpod/lib/src/notifier.dart @@ -21,6 +21,7 @@ abstract class NotifierBase { void _setElement(ProviderElementBase element); + /// {@template notifier.listen} /// Listens to changes on the value exposed by this provider. /// /// The listener will be called immediately after the provider completes building. @@ -28,6 +29,7 @@ abstract class NotifierBase { /// As opposed to [Ref.listen], the listener will be called even if /// [ProviderElementBase.updateShouldNotify] returns false, meaning that the previous /// and new value can potentially be identical. + /// {@endtemplate} void listenSelf( void Function(State? previous, State next) listener, { void Function(Object error, StackTrace stackTrace)? onError,