如何在 ListTile Flutter 中更改 inactive/disabled title/subtitle 的颜色?
How to change the color of inactive/disabled title/subtitle in ListTile Flutter?
我在 Flutter 中更改 disabled/inactive ListTile 的 title/subtitle/leading 的颜色时遇到问题。
我的小部件如下所示:
ListTile 有一个尾随的复选框并且已选中。 title/subtitle 的颜色是淡蓝色。我想改变这种颜色,但不知道如何。我试图用 ThemeData 改变它:
ThemeData(
textTheme: TextTheme(
subtitle1: TextStyle(
color: Colors.grey[500],
),
),
),
但它只适用于未选中的复选框,选中后 title/subtitle 变成浅蓝色,但我希望它是灰色的:( thic 颜色从哪里来的?我还能尝试什么?我想自从我升级Flutter到3.24.0后就出现了这个问题,之前一切正常。我在Flutter Web上,不幸的是不能使用DevTool Inspector
如果您正在使用 flutter 的 CheckboxListTile,请尝试在 flutter 中使用 row 创建自定义 ListTile,例如:
Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
Icon(Icons.account_box, color: Colors.white),
Expanded(
child: AutoSizeText(
data,
maxLines: 1,
style: TextStyle(
color: white,
),
)
),
Checkbox(
value: _serachSelectList.contains(data),
onChanged: (bool value) {
setState(() {
if (value) {
_serachSelectList.add(data);
setState((){ default_color = selected_color });
} else {
_serachSelectList.remove(data);
setState((){ default_color = unselected_color });
}
});
},
checkColor: Colors.green,
activeColor: Colors.transparent,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
]);
我刚刚找到了一个解决方案,但我认为可能还有另一个解决方案,也许使用 ThemeData,因此我可以为每个 ListTile 小部件定义颜色,而不使用其他小部件来更改它。
可以像这样使用 ListTileTheme 更改非活动 title/subtitle/leading 的颜色:
ListTileTheme(
selectedColor: Colors.grey,
child: ListTile(
leading: Icon(Icons.featured_play_list_outlined),
title: Text('Title'),
subtitle: Text('Subtitle'),
),
);
所以基本上我必须用 ListTileTheme 包装 ListTile 并使用 selectedColor 属性 它完成了工作!非活动 title/subtitle/leading 的颜色发生变化。
我在 Flutter 中更改 disabled/inactive ListTile 的 title/subtitle/leading 的颜色时遇到问题。
我的小部件如下所示:
ListTile 有一个尾随的复选框并且已选中。 title/subtitle 的颜色是淡蓝色。我想改变这种颜色,但不知道如何。我试图用 ThemeData 改变它:
ThemeData(
textTheme: TextTheme(
subtitle1: TextStyle(
color: Colors.grey[500],
),
),
),
但它只适用于未选中的复选框,选中后 title/subtitle 变成浅蓝色,但我希望它是灰色的:( thic 颜色从哪里来的?我还能尝试什么?我想自从我升级Flutter到3.24.0后就出现了这个问题,之前一切正常。我在Flutter Web上,不幸的是不能使用DevTool Inspector
如果您正在使用 flutter 的 CheckboxListTile,请尝试在 flutter 中使用 row 创建自定义 ListTile,例如:
Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
Icon(Icons.account_box, color: Colors.white),
Expanded(
child: AutoSizeText(
data,
maxLines: 1,
style: TextStyle(
color: white,
),
)
),
Checkbox(
value: _serachSelectList.contains(data),
onChanged: (bool value) {
setState(() {
if (value) {
_serachSelectList.add(data);
setState((){ default_color = selected_color });
} else {
_serachSelectList.remove(data);
setState((){ default_color = unselected_color });
}
});
},
checkColor: Colors.green,
activeColor: Colors.transparent,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
]);
我刚刚找到了一个解决方案,但我认为可能还有另一个解决方案,也许使用 ThemeData,因此我可以为每个 ListTile 小部件定义颜色,而不使用其他小部件来更改它。
可以像这样使用 ListTileTheme 更改非活动 title/subtitle/leading 的颜色:
ListTileTheme(
selectedColor: Colors.grey,
child: ListTile(
leading: Icon(Icons.featured_play_list_outlined),
title: Text('Title'),
subtitle: Text('Subtitle'),
),
);
所以基本上我必须用 ListTileTheme 包装 ListTile 并使用 selectedColor 属性 它完成了工作!非活动 title/subtitle/leading 的颜色发生变化。