在Flutter中,能否修改扩展瓷砖(Expansion Tile)?具体来说,我想删除它展开时创建的分隔线。此外,我还想调整其填充。是否有可能实现?谢谢!
在Flutter中,能否修改扩展瓷砖(Expansion Tile)?具体来说,我想删除它展开时创建的分隔线。此外,我还想调整其填充。是否有可能实现?谢谢!
从ExpansionTile
的源代码中获取
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
_borderColor.end = theme.dividerColor;
_headerColor
..begin = theme.textTheme.subhead.color
..end = theme.accentColor;
_iconColor
..begin = theme.unselectedWidgetColor
..end = theme.accentColor;
_backgroundColor.end = widget.backgroundColor;
您可以通过将元素包装在 Theme
中来影响您所能够影响的内容,例如通过修改 dividerColor
_borderColor.end = theme.dividerColor;
final theme = Theme.of(context).copyWith(dividerColor: Colors.yellow);
return Theme(data: theme, child: ExpansionTile(...));
与_headerColor
、_iconColor
和_backgroundColor
类似。
如果您需要更多自定义,您可以随时复制源代码并按照您的喜好进行自定义。
~/.pub-cache/...
或~/.flutter/...
中的代码,那么您在Flutter上将没有任何乐趣 - 根本不好玩 - 永远不要这样做。该目录中的更改可能随时丢失。如果您将源代码复制到自己的项目中,则维护负担就落在您身上,因为当Flutter团队进行更改时,您甚至不会收到通知,您的代码可能变得陈旧。如果小部件根本不允许以其他方式自定义其行为以满足您的需求(如上例所示),则复制可能是较小的负担。 - Günter Zöchbauer只需使用 Theme
widget 包装并将分隔线颜色设置为透明即可去除分割线。
final theme = Theme.of(context).copyWith(dividerColor: Colors.transparent);
return Theme(data: theme, child: ExpansionTile(...));
// border: Border(
// top: BorderSide(color: borderSideColor),
// bottom: BorderSide(color: borderSideColor),
// ),
来自 expansion_tile.dart