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

Flutter抽屉菜单点击报错:Cannot hit test a render box with no size

解决Flutter抽屉菜单「Cannot hit test a render box with no size.」错误

错误根源是你在Drawer的子组件中嵌套了Expanded——Expanded仅能在Row、Column这类Flex布局容器内生效,而Drawer本身已经为子组件分配了完整的可用空间,多余的Expanded会导致ListView无法正确计算自身尺寸,进而触发点击测试错误。

同时你的代码里还存在一个语法问题:ListView的children列表末尾多了一个多余的闭合括号,需要一并清理。

修正后的代码如下:

Widget menuDrawer() {
  return Drawer(
    child: ListView(
      padding: EdgeInsets.zero,
      children: <Widget>[
        UserAccountsDrawerHeader(
            decoration: BoxDecoration(color: Colors.pinkAccent),
            currentAccountPicture: GestureDetector(
              child: CircleAvatar(
                backgroundColor: Colors.white,
                child: Icon(Icons.person),
              ),
            ),
            accountName: Text("Sıla"),
            accountEmail: Text("silayldrm01@gmail.com")),
        ListTile(
          onTap: () {
            debugPrint("Ana Sayfa");
          },
          leading: Icon(
            Icons.home,
            color: Colors.green,
          ),
          title: Text(
            'Ana Sayfa',
            style: TextStyle(color: Colors.green),
          ),
        ),
      ],
    ),
  );
}

内容的提问来源于stack exchange,提问作者Sıla Yıldırım

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 09:05:14