Skip to content

Commit

Permalink
fix: infinite route push glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Aug 25, 2023
1 parent c3c09f5 commit e90eceb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/utils/service_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,19 @@ abstract class ServiceUtils {
}

static void navigate(BuildContext context, String location, {Object? extra}) {
if (GoRouterState.of(context).matchedLocation == location) return;
GoRouter.of(context).go(location, extra: extra);
}

static void push(BuildContext context, String location, {Object? extra}) {
GoRouter.of(context).push(location, extra: extra);
final router = GoRouter.of(context);
final routerState = GoRouterState.of(context);
final routerStack = router.routerDelegate.currentConfiguration.matches
.map((e) => e.matchedLocation);

if (routerState.matchedLocation == location ||
routerStack.contains(location)) return;
router.push(location, extra: extra);
}

static List<T> sortTracks<T extends Track>(List<T> tracks, SortBy sortBy) {
Expand Down

0 comments on commit e90eceb

Please sign in to comment.