自定义样式或主题,展开图块标题,颤振 [英] Custom style or theme for Expansion Tile Header, Flutter

查看:100
本文介绍了自定义样式或主题,展开图块标题,颤振的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以为ExpansionTile应用自定义主题.就我而言,我想让扩展图块的Header和孩子使用不同的背景颜色,但是ExpansionTile何时展开,Header背景颜色会变为孩子的颜色?

Is there any way to apply custom theme for ExpansionTile. In my case, I want to have the different background colour for Header and children of the expansion tile but When ever the ExpansionTile is expanded, Headers background color changes to that of children?

推荐答案

要将自定义主题应用于任何窗口小部件,只需将其与Theme()小部件一起包装即可. 然后在小部件的数据字段中指定您的自定义主题.

To apply a custom Theme to any widget, just wrap it with the Theme() widget. and then specify your custom theme in the data field of the widget.

Theme(
    data: ThemeData(/*specify your custom theme here*/),
    child: ExpansionTile() /*or any other widget you want to apply the theme to.*/
)

在您的情况下,要自定义ExpansionTile中的标头,

In your case, to customise the header in ExpansionTile,

ExpansionTile关闭时

  • 标题文本的样式,即标题取决于 ThemeData.textTheme.subhead
  • 而箭头图标的样式取决于 在ThemeData.unselectedWidget

when ExpansionTile is closed

  • the style of header text i.e. title depends on ThemeData.textTheme.subhead
  • whereas, the style of the arrow icon depends on ThemeData.unselectedWidget
  • 两个小部件的颜色取决于ThemeData.accentColor

以类似的方式,您可以通过调整主题来自定义扩展图块的几乎任何部分.有关更多详细信息,请查看此链接.

In a similar fashion you can customise almost any part of the expansion tile by tweaking the theme. For more details check out this link.

由于颤动是在考虑灵活性的基础上构建的.您几乎可以做任何您想做的事.创建几乎任何您想要的UI.

Since flutter is built with flexibility in mind. You can do almost anything you want. Create almost any UI you want.

这篇关于自定义样式或主题,展开图块标题,颤振的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆