go_router 页面跳转 参数传递

js 复制代码
  routes: <GoRoute>[
          GoRoute(
              name: 'family',
              path: 'family/:fid',
              builder: (BuildContext context, GoRouterState state) {
                return FamilyScreen(
                  fid: state.pathParameters['fid']!,
                  asc: state.uri.queryParameters['sort'] == 'asc',
                );
              }
          ),
        ],

1 通过state.pathParameters 获取path上设置的参数,比如fid,也可以设置多个参数 比如path 设置为 family/:fid/:aid 就可以通过 state.pathParameters'fid' 和 state.pathParameters'aid' 分别获取path上设置的fid 跟 aid

2 跳转方式

js 复制代码
context.go('/family/${entry.key}

或者

js 复制代码
context.goNamed('family',
                pathParameters: <String, String>{'fid': fid},
                queryParameters: newQueries)
相关推荐
用户21816970493014 小时前
Flutter ClipPath
flutter
用户21816970493016 小时前
Flutter 折叠组件 ExpansionTile ExpansionPanelList
flutter
不羁的木木2 天前
给鸿蒙 App 增加用系统应用打开文件的能力 —— open_app_file 的鸿蒙使用指南
flutter·harmonyos
HouWan2 天前
Flutter: MediaQuery.of(context) 为什么可能拖慢页面?
android·flutter·ios
西西学代码2 天前
flutter---井字游戏
flutter
tushanxing2 天前
Day 2: 容器与单子布局基础
flutter
程序员老刘3 天前
跨平台开发地图 | 2026年9月
flutter·客户端
HouWan3 天前
Flutter iOS UISceneDelegate 迁移指南:理清新的 Scene 生命周期
flutter·ios·app
技术任我行XTing3 天前
【DFX系列】Flutter 鸿蒙应用外接纹理介绍及问题定位
flutter·harmonyos