Skip to content

Commit a294012

Browse files
committed
fix(authentication): cancel cooldown timer when starting a new one
- Add _cooldownTimer field to store the timer reference - Cancel existing timer before starting a new one to prevent memory leaks - Update timer initialization to use the new _cooldownTimer field - Ensure timer is cancelled when the bloc is closed
1 parent bbcc0ed commit a294012

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/authentication/bloc/authentication_bloc.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class AuthenticationBloc
4747

4848
final AuthRepository _authenticationRepository;
4949
late final StreamSubscription<User?> _userAuthSubscription;
50+
Timer? _cooldownTimer;
5051

5152
/// Handles [_AuthenticationStatusChanged] events.
5253
Future<void> _onAuthenticationStatusChanged(
@@ -97,7 +98,8 @@ class AuthenticationBloc
9798
);
9899

99100
// Start a timer to transition out of cooldown
100-
Timer(
101+
_cooldownTimer?.cancel();
102+
_cooldownTimer = Timer(
101103
_requestCodeCooldownDuration,
102104
() => add(const AuthenticationCooldownCompleted()),
103105
);
@@ -213,6 +215,7 @@ class AuthenticationBloc
213215
@override
214216
Future<void> close() {
215217
_userAuthSubscription.cancel();
218+
_cooldownTimer?.cancel();
216219
return super.close();
217220
}
218221
}

0 commit comments

Comments
 (0)