有什么方法可以改变ExpansionPanelList.radio中图标的颜色吗?现在它是灰色的,它是不可见的,因为背景也是灰色的。
ExpansionPanelList.radio(
expandedHeaderPadding: const EdgeInsets.only(bottom: 5),
dividerColor: secondaryColor,
children: widget.items
.map(
(item) => ExpansionPanelRadio(
canTapOnHeader: true,
headerBuilder: (context, isExpanded) => ListTile(
title: Text(
item.name,
style: defTextStyle,
),
),
body: Column(
children: [],
),
value: item.name),
)
.toList(),
),发布于 2022-08-24 14:23:12
您始终可以将整个expansion_panel.dart作为custom_expansion_panel.dart复制到项目中的文件中。像import '../custom_expansion_panel' as custom一样将其导入您的文件。现在,在custom_文件中添加一个参数Color expansionIconColor;,然后ctrl+f搜索'expandIcon‘,并且它有一个color参数。只需指定expansionIconColor到它和瞧,你可以传递自定义图标颜色给它。
使用自定义类,如:custom.ExpansionPanelList.radio(...
如果需要,我可以为自定义展开面板列表创建一个gist或代码片段。
您可以随时查看this post,以供参考--它们有类似的问题。
发布于 2022-08-24 14:03:36
您需要在项目本身中更改这一点。我有点困惑,因为我在您的代码中任何地方都看不到图标。如果你在身体里放了一个ListTile,你可以把你的图标传递给尾随参数,如下所示;
widget.items.map<ExpansionPanelRadio>((Item item) {
return ExpansionPanelRadio(
value: item.id,
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text(item.headerValue),
);
},
body: ListTile(
title: Text(item.expandedValue),
subtitle:
const Text('To delete this panel, tap the trash can icon'),
trailing: const Icon(Icons.delete),
onTap: () {
setState(() {
_data
.removeWhere((Item currentItem) => item == currentItem);
});
}));
}).toList(),也许类似于这种方法的东西就是你要找的东西?
发布于 2022-08-24 14:16:37
这个值是硬编码的,无线电平铺不需要任何参数。第360-368行
Widget expandIconContainer = Container(
margin: const EdgeInsetsDirectional.only(end: 8.0),
child: ExpandIcon(
/// color: you can include color here and pass from constructor. make sure to import material
isExpanded: _isChildExpanded(index),
padding: const EdgeInsets.all(16.0),
onPressed: !child.canTapOnHeader
? (bool isExpanded) => _handlePressed(isExpanded, index)
: null,
),
);ExpandIcon的颜色取决于ThemeData.brightness,如果你不把颜色传递给它。
Color get _iconColor {
if (widget.isExpanded && widget.expandedColor != null) {
return widget.expandedColor!;
}
if (widget.color != null) {
return widget.color!;
}
switch(Theme.of(context).brightness) {
case Brightness.light:
return Colors.black54;
case Brightness.dark:
return Colors.white60;
}
}颜色是从这里硬编码到IconButton的.我现在想到的解决方案是创建一个本地文件并在expandIconContainer上添加颜色(第一部分)
https://stackoverflow.com/questions/73474302
复制相似问题