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

Flutter应用中无法显示复选框及对应文本问题求助

问题原因与解决方法

你看不到复选框的核心原因是:你定义了TaskList组件,但从未在页面的Widget树中使用它。当前MyHomePage的body里只放了MyProgress,所以只有进度指示器会被渲染。

解决步骤

修改MyHomePage的build方法,在Column的children数组中添加TaskList()即可:

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Checkbox'),
      ),
      body: Column(
        children: [
          MyProgress(),
          TaskList(), // 新增这一行,引入复选框列表
        ],
      ),
    );
  }
}

额外建议

如果后续复选框列表项增多,直接用Column可能会导致页面溢出,建议用以下两种方式优化:

方案1:用SingleChildScrollView包裹

body: SingleChildScrollView(
  child: Column(
    children: [
      MyProgress(),
      TaskList(),
    ],
  ),
),

方案2:换成ListView

body: ListView(
  children: [
    MyProgress(),
    TaskList(),
  ],
),

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 10:40:35