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

Flutter应用启动报错:RenderCustomMultiChildLayoutBox子项需含父数据ID

问题解决:Every child of a RenderCustomMultiChildLayoutBox must have an ID in its parent data

错误根源

  • Expanded不能直接作为Scaffold的body:Expanded是Row/Column这类Flex布局的专属子组件,直接嵌套在Scaffold的body中会破坏布局结构逻辑。
  • Row子组件未明确空间分配:Row中的NavigationRail和SignUpPage没有设置空间分配规则,导致NavigationRail内部的CustomMultiChildLayout系统无法识别子组件的布局标识,触发错误。

修正后的代码

Widget build(BuildContext context) {
  return Scaffold(
    body: Row(
      children: [
        SafeArea(
          child: NavigationRail(
            selectedIndex: 0,
            onDestinationSelected: (int index) {
              print('Test');
            },
            destinations: const [
              NavigationRailDestination(
                icon: Icon(Icons.home),
                label: Text("Home"),
              ),
              NavigationRailDestination(
                icon: Icon(Icons.home),
                label: Text("a"),
              ),
            ],
          ),
        ),
        // 用Expanded包裹SignUpPage,让它占据Row的剩余空间
        const Expanded(
          child: SignUpPage(),
        ),
      ],
    ),
  );
}

额外提示

如果SignUpPage内部包含Scaffold组件,建议移除内部的Scaffold——嵌套Scaffold容易引发布局冲突(比如重复的导航栏、背景层),直接用Container或其他基础布局组件作为根节点即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 21:45:01