calculateOrgSelectedIndex function
- BuildContext context,
- String? orgId
Returns the selected index for the org bottom-nav / rail, or null when
the current route is a detail screen (/org/:orgId/notifications,
/org/:orgId/teams, etc.) that doesn't correspond to any of the five
shell destinations. Callers that need a non-null value (e.g. the main
shell) should fall back to 0 (Dashboard).
Implementation
int? calculateOrgSelectedIndex(BuildContext context, String? orgId) {
if (orgId == null) return 0;
final location = GoRouterState.of(context).uri.toString();
if (location == '/org/$orgId') return 0; // Dashboard
if (location.startsWith('/org/$orgId/members')) {
// /members is the index destination, /members/:userId is a detail page.
return location == '/org/$orgId/members' ? 1 : null;
}
if (location.startsWith('/org/$orgId/assignments')) {
return location == '/org/$orgId/assignments' ? 2 : null;
}
if (location.startsWith('/org/$orgId/analytics')) return 3;
if (location.startsWith('/org/$orgId/settings')) return 4;
return null;
}