如何更改CircularProgressIndicator的颜色?
颜色的值是Animation< color >的实例,但我希望有一种更简单的方法来改变颜色,没有动画的麻烦。
如何更改CircularProgressIndicator的颜色?
颜色的值是Animation< color >的实例,但我希望有一种更简单的方法来改变颜色,没有动画的麻烦。
当前回答
在主。dart设置主题为accentColor, CircularProgressIndicator将使用该颜色
void main() => runApp(new MaterialApp(
theme: ThemeData(primaryColor: Colors.red, **accentColor: Colors.yellowAccent**),
debugShowCheckedModeBanner: false,
home: SplashPage()
));
其他回答
accentColor已弃用,不再有效。
要在ThemeData中全局设置它,像这样设置:
光的主题:
theme: ThemeData(
colorScheme: ColorScheme.dark(
primary: Colors.pink,
),
),
黑暗的主题:
theme: ThemeData(
colorScheme: ColorScheme(
primary: Colors.pink,
),
),
本地:
或者如果你想要它只用于本地的一个小部件,只需要像这样设置CircularProgressIndicator的属性:
CircularProgressIndicator(
backgroundColor:Colors.white,
valueColor: AlwaysStoppedAnimation<Color>(Colors.pink),
),
只需将此代码写入应用程序的主题数据
ThemeData(
progressIndicatorTheme: ProgressIndicatorThemeData(
color: Colors.grey.shade700,),)
valueColor:new AlwaysStoppedAnimation<Color>(Colors.yellow),
试试这个:
CircularProgressIndicator(
color: Colors.yellow, // Change your color here
),
主题是可以插入到小部件树中的任何位置的小部件。 它用自定义值覆盖当前主题 试试这个:
new Theme(
data: Theme.of(context).copyWith(accentColor: Colors.yellow),
child: new CircularProgressIndicator(),
);
参考:https://gitter.im/flutter/flutter?at=5a84cf9218f388e626a51c2d