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

Flutter如何修改禁用/未激活状态下ListTile的标题与副标题颜色

ListTile Widget

浅蓝色样式来源

该样式是Flutter 3.24版本对ListTile组件选中态逻辑更新后产生的:当ListTile的selected属性为true(和你绑定的Checkbox勾选状态联动)时,组件会优先使用ListTileTheme中配置的selectedColor对title、subtitle、leading等元素染色,默认取值为主题的ColorScheme.primary,也就是你看到的浅蓝色。你此前配置的全局textTheme不生效,是因为选中态的样式优先级高于普通文本主题配置。

可行修改方案

  • 方案1:全局配置统一生效
    在根ThemeData中新增listTileTheme配置,直接指定选中态颜色即可,原有其他主题配置可保留:
    ThemeData(
      listTileTheme: ListTileThemeData(
        // 选中状态下的文本、图标颜色
        selectedColor: Colors.grey[500],
        // 若需修改禁用状态的颜色也可同步配置
        // disabledColor: Colors.grey[700],
      ),
      textTheme: TextTheme(
        subtitle1: TextStyle(
          color: Colors.grey[500],
        ),
      ),
    )
    
  • 方案2:局部修改指定ListTile样式
    不需要全局生效的场景下,可以给目标ListTile外层套ListTileTheme组件单独配置:
    ListTileTheme(
      data: ListTileThemeData(
        selectedColor: Colors.grey[500],
      ),
      child: ListTile(
        selected: yourCheckValue,
        leading: Icon(Icons.your_icon),
        title: Text("标题"),
        subtitle: Text("副标题"),
        trailing: Checkbox(
          value: yourCheckValue,
          onChanged: (v) {
            // 勾选逻辑处理
          },
        ),
      ),
    )
    
  • 方案3:直接指定ListTile文本样式
    也可以通过ListTile自带的样式属性直接覆盖选中态逻辑:
    ListTile(
      selected: yourCheckValue,
      title: Text("标题"),
      subtitle: Text("副标题"),
      titleTextStyle: TextStyle(
        color: Colors.grey[500],
      ),
      subtitleTextStyle: TextStyle(
        color: Colors.grey[500],
      ),
      trailing: Checkbox(
        value: yourCheckValue,
        onChanged: (v) {
          // 勾选逻辑处理
        },
      ),
    )
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.12 06:57:00