From 099aecb7ac76e654943b8ed1643bcebf712b0847 Mon Sep 17 00:00:00 2001 From: Henrique Velloso Date: Thu, 12 Feb 2026 09:49:54 -0300 Subject: [PATCH] hotfix: Defer package synchronization in router to avoid state modification during build phase --- lib/router.dart | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/router.dart b/lib/router.dart index 0c1caed..787c009 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -12,6 +12,7 @@ import 'package:zapstore/screens/search_screen.dart'; import 'package:zapstore/screens/updates_screen.dart'; import 'package:zapstore/screens/profile_screen.dart'; import 'package:zapstore/services/package_manager/package_manager.dart'; + /// Root paths for each navigation branch (used for back navigation handling) const kBranchRoots = ['/search', '/updates', '/profile']; @@ -140,18 +141,20 @@ final routerProvider = Provider((ref) { final wasUpdatesRoute = previousPath?.startsWith('/updates') ?? false; previousPath = currentPath; - // Sync installed packages on every navigation to catch sideloads, - // external installs/uninstalls, and self-updating apps. - // This is a local-only platform channel call (~100-500ms, no network). - unawaited( - ref.read(packageManagerProvider.notifier).syncInstalledPackages(), - ); + Future.microtask(() { + // Sync installed packages on every navigation to catch sideloads, + // external installs/uninstalls, and self-updating apps. + // This is a local-only platform channel call (~100-500ms, no network). + unawaited( + ref.read(packageManagerProvider.notifier).syncInstalledPackages(), + ); - // Clear completed operations when navigating AWAY from updates - // This cleans up the "All done" state without affecting the count while visible - if (wasUpdatesRoute && !isUpdatesRoute) { - ref.read(packageManagerProvider.notifier).clearCompletedOperations(); - } + // Clear completed operations when navigating AWAY from updates + // This cleans up the "All done" state without affecting the count while visible + if (wasUpdatesRoute && !isUpdatesRoute) { + ref.read(packageManagerProvider.notifier).clearCompletedOperations(); + } + }); } router.routerDelegate.addListener(onRouteChange);