Skip to content

Commit 0cf7337

Browse files
committed
refactor(app): replace Random ID generation with UUID
- Remove unnecessary import of dart:math - Add uuid package to dependencies - Update InAppNotification ID generation to use UUID instead of random number - Add Uuid as a dependency in AppBloc constructor
1 parent a417279 commit 0cf7337

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/app/bloc/app_bloc.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'dart:async';
2-
import 'dart:math';
32

43
import 'package:auth_repository/auth_repository.dart';
54
import 'package:core/core.dart';
@@ -15,6 +14,7 @@ import 'package:flutter_news_app_mobile_client_full_source_code/app/services/app
1514
import 'package:flutter_news_app_mobile_client_full_source_code/notifications/services/push_notification_service.dart';
1615
import 'package:flutter_news_app_mobile_client_full_source_code/shared/extensions/extensions.dart';
1716
import 'package:logging/logging.dart';
17+
import 'package:uuid/uuid.dart';
1818

1919
part 'app_event.dart';
2020
part '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

Comments
 (0)