From 55ff65ba3201053ef5462a96b1c656f889e209f1 Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Wed, 14 May 2025 11:11:45 +0200 Subject: [PATCH] Remove unnecessary notifyListeners calls Signed-off-by: Hans Kokx --- example/lib/services/favorite_color_service.dart | 2 -- .../authentication/authentication_service.dart | 2 -- .../feature_flags/feature_flags_service.dart | 14 +++++--------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/example/lib/services/favorite_color_service.dart b/example/lib/services/favorite_color_service.dart index c9f2193..ac838cc 100644 --- a/example/lib/services/favorite_color_service.dart +++ b/example/lib/services/favorite_color_service.dart @@ -20,8 +20,6 @@ class FavoriteColorService extends ArcaneService { if (_notifier.value != newValue) { _notifier.value = newValue; } - - notifyListeners(); } } diff --git a/lib/src/services/authentication/authentication_service.dart b/lib/src/services/authentication/authentication_service.dart index 31974bc..6ad8045 100644 --- a/lib/src/services/authentication/authentication_service.dart +++ b/lib/src/services/authentication/authentication_service.dart @@ -67,7 +67,6 @@ class ArcaneAuthenticationService extends ArcaneService { _notifier.value = AuthenticationStatus.unauthenticated; _isSignedIn.value = isAuthenticated; _previousModeWhenSettingDebug = null; - notifyListeners(); } /// Registers an `ArcaneAuthInterface` within the `ArcaneAuthenticationService`. @@ -157,7 +156,6 @@ class ArcaneAuthenticationService extends ArcaneService { _notifier.value = newStatus; _isSignedIn.value = isAuthenticated; } - notifyListeners(); } /// Logs the current user out. Upon successful logout, `status` will be set to diff --git a/lib/src/services/feature_flags/feature_flags_service.dart b/lib/src/services/feature_flags/feature_flags_service.dart index ec04657..93544fc 100644 --- a/lib/src/services/feature_flags/feature_flags_service.dart +++ b/lib/src/services/feature_flags/feature_flags_service.dart @@ -82,7 +82,6 @@ class ArcaneFeatureFlags extends ArcaneService { ); } - notifyListeners(); return I; } @@ -111,7 +110,6 @@ class ArcaneFeatureFlags extends ArcaneService { ); } - notifyListeners(); return I; } @@ -121,12 +119,9 @@ class ArcaneFeatureFlags extends ArcaneService { /// It is called automatically when enabling or disabling features if they haven't /// already been initialized. void _init() { - _notifier.value = []; - - notifier.addListener(_listener); - + if (I._initialized) return; + reset(); I._initialized = true; - notifyListeners(); } /// Resets the feature flags to their initial state. @@ -134,10 +129,11 @@ class ArcaneFeatureFlags extends ArcaneService { /// This method clears all enabled features, resets notification values, /// marks the flags as uninitialized, and notifies listeners of the changes. void reset() { + notifier + ..removeListener(_listener) + ..addListener(_listener); _notifier.value = []; - I._initialized = false; - notifyListeners(); } void _listener() {