40

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

如果我想要一个具有自定义颜色的 LinearProgressIndicator,我需要创建自己的类吗?真的没有办法指定这个吗?

4

4 回答 4

94

如果要设置恒定颜色,可以使用:

CircularProgressIndicator(
  valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
)
于 2018-01-15T14:35:13.123 回答
14

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

将相关子树包装在修改后的 Theme 中,将 AccentColor 设置为您可能喜欢的任何内容。

于 2016-12-09T21:17:34.793 回答
9
LinearProgressIndicator(backgroundColor: Color(0xFFB4B4B4),valueColor:new AlwaysStoppedAnimation<Color>(Colors.green),),

于 2019-12-17T15:22:39.103 回答
4

我认为您可以通过以下方式提供,

LinearProgressIndicator( valueColor: AlwaysStoppedAnimation<Color> (Color(0xFFA86E52)),),
于 2019-01-28T11:10:47.740 回答