You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中从启动页跳转至StatefulShellRoute.indexedStack路由的方法

路由跳转问题解决方案

问题原因

你当前的context.goNamed('home')无法生效,是因为路由配置里没有名为home的路由,而且StatefulShellRoute.indexedStack作为壳路由本身不需要独立命名,它是通过下属的StatefulShellBranch路由来触发加载HomeScreen的。

解决步骤

直接跳转到StatefulShellBranch下已定义的具体路由即可,比如你配置的第一个分支account路由:

修改后的splash_screen.dart代码

Timer(
  const Duration(seconds: 3),
  () {
    isOnboardingCompleted 
        ? isLoggedIn 
            ? context.goNamed('account') // 替换home为已定义的分支路由名称account
            : context.goNamed('signin')
        : context.goNamed('onboarding');
  },
);

补充说明

  1. StatefulShellRoute.indexedStack是底部导航的壳容器,当你跳转到它下属任意一个分支路由(比如/account)时,GoRouter会自动加载HomeScreen并显示对应分支的页面。
  2. 后续新增底部导航页面时,只需在branches中添加新的StatefulShellBranch,跳转对应分支的路由名称即可。

内容的提问来源于stack exchange,提问作者Mehedi Hasan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 02:52:26