如何设置 LinearProgressIndicator 的动画颜色?

How do I set the animation color of a LinearProgressIndicator?

LinearProgressIndicator documentation 有助于显示 valueColor 属性 的存在,甚至提到“要指定常量颜色,请使用:new AlwaysStoppedAnimation(color)。”,但如果我尝试设置颜色我得到一个错误,LinearProgressIndicator 没有实例 setter for valueColor 并且 class 的构造函数只接受一个键和一个进度量的数值。

如果我想要具有自定义颜色的 LinearProgressIndicator,是否需要创建自己的 class?真的没有办法指定吗?

看起来它是由主题强调色控制的: https://github.com/flutter/flutter/blob/b670ce4bcc49bbab745221eae24fcebcbc9dba7c/packages/flutter/lib/src/material/progress_indicator.dart#L61

将相关子树包装在修改后的主题中,将强调色设置为您可能喜欢的任何颜色。

如果你想设置一个固定的颜色,你可以使用:

CircularProgressIndicator(
  valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
)

我想你可以通过以下方式提供,

LinearProgressIndicator( valueColor: AlwaysStoppedAnimation<Color> (Color(0xFFA86E52)),),
LinearProgressIndicator(
    backgroundColor: Color(0xFFB4B4B4),
    valueColor: AlwaysStoppedAnimation<Color>(Colors.green),
)