颤振:自定义ExpansionTile

nyp*_*ogi 4 dart flutter

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

Tar*_*rma 24

对于删除分隔线,只需使用Theme小部件扭曲并使分隔线颜色透明。

final theme = Theme.of(context).copyWith(dividerColor: Colors.transparent);
return Theme(data: theme, child: ExpansionTile(...));    
Run Code Online (Sandbox Code Playgroud)


Gün*_*uer 15

来源 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;
Run Code Online (Sandbox Code Playgroud)

您可以Theme通过修改包装元素来推导出您可以影响的内容dividerColor

_borderColor.end = theme.dividerColor;
Run Code Online (Sandbox Code Playgroud)
final theme = Theme.of(context).copyWith(dividerColor: Colors.yellow);
return Theme(data: theme, child: ExpansionTile(...));     
Run Code Online (Sandbox Code Playgroud)

类似的_headerColor,_iconColor,_backgroundColor.如果您需要更多自定义,您可以随时复制源并根据自己的喜好对其进行自定义.