Skip to content

Commit e3c026a

Browse files
committed
refactor(entity_details): improve redirect path handling and update limit reached logic
- Replace direct access to routerDelegate with GoRouter.of() for better null safety - Add null checks before accessing routerDelegate to prevent potential crashes - Add comments to clarify the early return pattern for limit reached scenarios
1 parent 04254c7 commit e3c026a

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

lib/entity_details/bloc/entity_details_bloc.dart

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,16 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
244244
extra: LimitReachedArguments(
245245
limitType: LimitType.followedTopics,
246246
userRole: userRole,
247-
redirectPath: _appBloc.navigatorKey.currentContext?.routerDelegate
248-
.currentConfiguration.uri.toString(),
247+
redirectPath: _appBloc.navigatorKey.currentContext != null
248+
? GoRouter.of(_appBloc.navigatorKey.currentContext!)
249+
.routerDelegate
250+
.currentConfiguration
251+
.uri
252+
.toString()
253+
: null,
249254
),
250255
);
251-
return;
256+
return; // Stop further processing
252257
}
253258
updatedFollowedTopics.add(topic);
254259
isCurrentlyFollowing = true;
@@ -275,11 +280,16 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
275280
extra: LimitReachedArguments(
276281
limitType: LimitType.followedSources,
277282
userRole: userRole,
278-
redirectPath: _appBloc.navigatorKey.currentContext?.routerDelegate
279-
.currentConfiguration.uri.toString(),
283+
redirectPath: _appBloc.navigatorKey.currentContext != null
284+
? GoRouter.of(_appBloc.navigatorKey.currentContext!)
285+
.routerDelegate
286+
.currentConfiguration
287+
.uri
288+
.toString()
289+
: null,
280290
),
281291
);
282-
return;
292+
return; // Stop further processing
283293
}
284294
updatedFollowedSources.add(source);
285295
isCurrentlyFollowing = true;
@@ -306,11 +316,16 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
306316
extra: LimitReachedArguments(
307317
limitType: LimitType.followedCountries,
308318
userRole: userRole,
309-
redirectPath: _appBloc.navigatorKey.currentContext?.routerDelegate
310-
.currentConfiguration.uri.toString(),
319+
redirectPath: _appBloc.navigatorKey.currentContext != null
320+
? GoRouter.of(_appBloc.navigatorKey.currentContext!)
321+
.routerDelegate
322+
.currentConfiguration
323+
.uri
324+
.toString()
325+
: null,
311326
),
312327
);
313-
return;
328+
return; // Stop further processing
314329
}
315330
updatedFollowedCountries.add(country);
316331
isCurrentlyFollowing = true;

0 commit comments

Comments
 (0)