颤动:自定义ExpansionTile

问题描述 投票:3回答:2

是否可以改变颤振的膨胀瓦?具体来说,我想删除它扩展时创建的分隔符。我也想调整它的填充。那可能吗?谢谢!

dart flutter
2个回答
9
投票

来自ExpansionTile的来源

https://github.com/flutter/flutter/blob/d927c9331005f81157fa39dff7b5dab415ad330b/packages/flutter/lib/src/material/expansion_tile.dart#L176-L184

  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相似。如果您需要更多自定义,您可以随时复制源并根据自己的喜好对其进行自定义。


1
投票

只需从https://github.com/flutter/flutter/blob/d927c9331005f81157fa39dff7b5dab415ad330b/packages/flutter/lib/src/material/expansion_tile.dart#L176-L184复制ExpansionTile源代码并根据需要进行编辑,然后制作自定义ExpansionTile !!

© www.soinside.com 2019 - 2024. All rights reserved.