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

Flutter技术求助:SingleChildScrollView组件无法滚动

解决Flutter横向SingleChildScrollView无法滚动的问题

你的横向滚动失效核心原因是:包裹SingleChildScrollView的容器没有设置宽度约束,导致容器自动拉伸至内部Row的总宽度,SingleChildScrollView失去了触发滚动的空间条件。

修复方案

直接用Expanded包裹SingleChildScrollView,让它占据Column剩余的垂直空间,同时横向被约束为屏幕宽度,当内部按钮总宽度超出屏幕时,滚动功能自动生效:

修改主文件中body部分的代码:

body: Column(
  children: [
    Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        ContainerHomePage('Name1', '20H'),
        ContainerHomePage('Name1', '20H'),
        ContainerHomePage('Name1', '20H'),
      ],
    ),
    // 替换原Container+SingleChildScrollView部分
    Expanded(
      child: SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        child: Row(
          children: [
            ButtonChoise('name'),
            ButtonChoise('name'),
            ButtonChoise('name'),
            ButtonChoise('name'),
            ButtonChoise('name'),
            ButtonChoise('name'),
            ButtonChoise('name'),
            ButtonChoise('name'),
            ButtonChoise('name'),
            ButtonChoise('name'),
          ],
        ),
      ),
    ),
  ],
),

替代方案(固定高度)

如果不想让滚动区域占满剩余空间,也可以给SingleChildScrollView设置固定高度和屏幕宽度:

Container(
  width: MediaQuery.of(context).size.width,
  height: 50, // 适配按钮高度,可按需调整
  child: SingleChildScrollView(
    scrollDirection: Axis.horizontal,
    child: Row(/* 按钮列表 */),
  ),
)

内容的提问来源于stack exchange,提问作者Łukasz Szumowski

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 23:45:41