Skip to content

Commit f057682

Browse files
authored
Merge pull request #35 from flutter-news-app-full-source-code/enhance_auth_feature
Enhance auth feature
2 parents 16024dd + a294012 commit f057682

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
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
}

lib/authentication/view/request_code_page.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,8 @@ class _EmailLinkFormState extends State<_EmailLinkForm> {
222222
setState(() {
223223
_cooldownSeconds = 0;
224224
});
225-
// Optionally, trigger an event to reset the bloc state if needed
226-
context
227-
.read<AuthenticationBloc>()
228-
.add(const AuthenticationCooldownCompleted());
225+
// The BLoC handles resetting its own state. The UI timer is only
226+
// responsible for updating the countdown on the screen.
229227
}
230228
});
231229
}

0 commit comments

Comments
 (0)