Skip to content

Commit d4095b8

Browse files
committed
fix(app): check if mounted before adding events in subscriptions
- Add null safety check for widget lifecycle state in user subscription - Add null safety check for push notification subscription
1 parent 3156182 commit d4095b8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/app/view/app.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,22 @@ class _AppViewState extends State<_AppView> {
201201
// Subscribe to the authentication repository's authStateChanges stream.
202202
// This stream is the single source of truth for the user's auth state
203203
// and drives the entire app lifecycle by dispatching AppUserChanged events.
204-
_userSubscription = context.read<AuthRepository>().authStateChanges.listen(
205-
(user) => context.read<AppBloc>().add(AppUserChanged(user)),
206-
);
204+
_userSubscription = context.read<AuthRepository>().authStateChanges.listen((
205+
user,
206+
) {
207+
if (mounted) {
208+
context.read<AppBloc>().add(AppUserChanged(user));
209+
}
210+
});
207211

208212
// Subscribe to foreground push notifications. When a message is received,
209213
// dispatch an event to the AppBloc to update the UI state (e.g., show an
210214
// indicator dot).
211-
_onMessageSubscription = pushNotificationService.onMessage.listen(
212-
(_) => context.read<AppBloc>().add(const AppInAppNotificationReceived()),
213-
);
215+
_onMessageSubscription = pushNotificationService.onMessage.listen((_) {
216+
if (mounted) {
217+
context.read<AppBloc>().add(const AppInAppNotificationReceived());
218+
}
219+
});
214220

215221
// Subscribe to notifications that are tapped and open the app.
216222
// This is the core of the deep-linking functionality.

0 commit comments

Comments
 (0)