【问题标题】:Changing the trailing icon color in ExpansionTile更改 ExpansionTile 中的尾随图标颜色
【发布时间】:2021-03-12 09:26:36
【问题描述】:

我需要更改ExpansionTile 中尾随keyboard_down_arrow 的颜色。我已经尝试将它包装在主题小部件中并设置口音、主要和图标主题,但似乎没有任何效果。

Theme(
                  data: Theme.of(context).copyWith(
                    dividerColor: Colors.transparent,
                    accentColor: Colors.black,
                  ),
                  child: ExpansionTile(
                    //
                    title: Text("Some Text"
                    ),
                    childrenPadding: EdgeInsets.symmetric(horizontal: 15),
                    children: [
                      
                    ],
                  ),
                ),

【问题讨论】:

  • 你能分享一些代码吗?
  • 查看我编辑的问题

标签: flutter flutter-design


【解决方案1】:

要更改尾随图标的颜色,您可以使用 Expansion Tile 中的 fallowing 参数

 trailing: Icon(
              Icons.keyboard_arrow_down,
              color: Colors.green,
            ),

示例:

 ExpansionTile(
                //
                title: Text("Some Text"),
                trailing: Icon(
                  Icons.keyboard_arrow_down,
                  color: Colors.green,
                ),
              ),

对于主题颜色使用color: Theme.of(context).primaryColor,

【讨论】:

  • 这将使箭头图标静止并且不再旋转。
【解决方案2】:

我找到了解决上述问题的方法。

在 Flutter 中将 unselectedWidgetColor 属性设置为你想要的 Theme 类的颜色。

【讨论】:

  • 很高兴知道您找到了解决方案。干杯
  • 您还知道如何更改“向上箭头”的颜色吗?那么unselectedWidgetColor的反面呢?谢谢
  • 在此评论中找到了一种方法:github.com/flutter/flutter/issues/23053#issuecomment-606957087 将 ExpansionTile 包装在主题小部件中。例如:主题(数据:ThemeData(accentColor:Colors.black54),孩子:ExpansionTile())
【解决方案3】:

我有打开/关闭状态的最新解决方案:

Theme(
    data: Theme.of(context).copyWith(
      unselectedWidgetColor: Colors.white, // here for close state
      colorScheme: ColorScheme.light(
          primary: Colors.white,
      ), // here for open state in replacement of deprecated accentColor
      dividerColor: Colors.transparent, // if you want to remove the border
    ),
    child: ExpansionTile(
        ...
    ),
),...

【讨论】:

  • 改变颜色Sheme作品
猜你喜欢
  • 2021-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-11
  • 2018-05-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多