11import 'dart:async' ;
2- import 'dart:math' ;
32
43import 'package:auth_repository/auth_repository.dart' ;
54import 'package:core/core.dart' ;
@@ -15,6 +14,7 @@ import 'package:flutter_news_app_mobile_client_full_source_code/app/services/app
1514import 'package:flutter_news_app_mobile_client_full_source_code/notifications/services/push_notification_service.dart' ;
1615import 'package:flutter_news_app_mobile_client_full_source_code/shared/extensions/extensions.dart' ;
1716import 'package:logging/logging.dart' ;
17+ import 'package:uuid/uuid.dart' ;
1818
1919part 'app_event.dart' ;
2020part 'app_state.dart' ;
@@ -49,6 +49,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
4949 required DataRepository <User > userRepository,
5050 required PushNotificationService pushNotificationService,
5151 required DataRepository <InAppNotification > inAppNotificationRepository,
52+ Uuid ? uuid,
5253 }) : _remoteConfigRepository = remoteConfigRepository,
5354 _appInitializer = appInitializer,
5455 _authRepository = authRepository,
@@ -57,6 +58,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
5758 _userRepository = userRepository,
5859 _inAppNotificationRepository = inAppNotificationRepository,
5960 _pushNotificationService = pushNotificationService,
61+ _uuid = uuid ?? const Uuid (),
6062 _inlineAdCacheService = inlineAdCacheService,
6163 _logger = logger,
6264 super (
@@ -110,8 +112,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
110112 try {
111113 final newNotification = InAppNotification (
112114 // Generate a random ID for the notification.
113- // In a real-world scenario, this would likely be a UUID.
114- id: Random ().nextInt (999999 ).toString (),
115+ id: _uuid.v4 (),
115116 userId: state.user! .id,
116117 payload: payload,
117118 createdAt: DateTime .now (),
@@ -147,6 +148,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
147148 final DataRepository <User > _userRepository;
148149 final DataRepository <InAppNotification > _inAppNotificationRepository;
149150 final PushNotificationService _pushNotificationService;
151+ final Uuid _uuid;
150152 final InlineAdCacheService _inlineAdCacheService;
151153
152154 /// Handles the [AppStarted] event.
0 commit comments