Flutter:自定义ExpansionTile

时间:2018-09-13 02:42:40

标签: dart flutter

是否可以在颤动中更改扩展图块?具体来说,我想删除它在扩展时创建的分隔线。我也想调整其填充。那可能吗?谢谢!

3 个答案:

答案 0 :(得分: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 :(得分:1)

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

答案 2 :(得分:0)

评论

//        border: Border(
//          top: BorderSide(color: borderSideColor),
//          bottom: BorderSide(color: borderSideColor),
//        ),

来自expandation_tile.dart

相关问题