From d0505cb6c03e4677d45e8de61eaa6788fbeee7c5 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 26 May 2026 11:07:26 +0000 Subject: [PATCH] fix(navigation): clamp navigateViewGroup index before PageController.jumpToPage NavigateViewGroupAction passed script-provided viewIndex directly to jumpToPage, which asserts when the index is outside the tab range (e.g. bottom nav with reloadView=false). Reuse safeViewGroupPayloadIndex with the ancestor PageGroup menu length so the notifier and PageController stay aligned. Co-authored-by: Sharjeel Yunus --- modules/ensemble/lib/framework/action.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/ensemble/lib/framework/action.dart b/modules/ensemble/lib/framework/action.dart index 677eaf3d2..bafd15cc7 100644 --- a/modules/ensemble/lib/framework/action.dart +++ b/modules/ensemble/lib/framework/action.dart @@ -168,14 +168,19 @@ class NavigateViewGroupAction extends EnsembleAction { ScreenController() .navigateToScreen(context, screenName: screenName, pageArgs: payload); } else if (viewIndex != null) { + final pageGroup = context.findAncestorWidgetOfExactType(); + final menuLen = pageGroup?.menu.menuItems.length ?? 0; + final resolvedIndex = menuLen > 0 + ? safeViewGroupPayloadIndex(viewIndex, menuLen) + : viewIndex; if (payload != null) { // TODO: this is wrong. Can't mutate the scope like this scopeManager.dataContext.addDataContext(payload); } // TODO: refactor the below. Both are needed when reloadView=false, but only // viewGroupNotifier is needed without. Doesn't make any sense - PageGroupWidget.getPageController(context)?.jumpToPage(viewIndex); - viewGroupNotifier.updatePage(viewIndex, payload: payload); + PageGroupWidget.getPageController(context)?.jumpToPage(resolvedIndex); + viewGroupNotifier.updatePage(resolvedIndex, payload: payload); } return Future.value(null); }