如何更改CircularProgressIndicator的颜色?
颜色的值是Animation< color >的实例,但我希望有一种更简单的方法来改变颜色,没有动画的麻烦。
如何更改CircularProgressIndicator的颜色?
颜色的值是Animation< color >的实例,但我希望有一种更简单的方法来改变颜色,没有动画的麻烦。
当前回答
解决问题的三种方法
1)使用valueColor属性
CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(Colors.blue),
),
2)在MaterialApp主部件中设置accentColor。 这是最好的方法,因为当你使用CircularProgressIndicator小部件时,你不想一直设置颜色
MaterialApp(
title: 'My App',
home: MainPAge(),
theme: ThemeData(accentColor: Colors.blue),
),
3)使用主题小部件
Theme(
data: Theme.of(context).copyWith(colorScheme: ColorScheme(
primary: Colors.red,
// You should set other properties too
)),
child: new CircularProgressIndicator(),
)
其他回答
可以使用accentColor作为widget的前景色。它可以改变任何前景小部件的颜色,包括circularprogressbar。
void main() => runApp(
MaterialApp(
title: 'Demo App',
home: MainClass(),
theme: ThemeData(accentColor: Colors.black),
),
);
在主。dart设置主题为accentColor, CircularProgressIndicator将使用该颜色
void main() => runApp(new MaterialApp(
theme: ThemeData(primaryColor: Colors.red, **accentColor: Colors.yellowAccent**),
debugShowCheckedModeBanner: false,
home: SplashPage()
));
这招对我很管用:
CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(Colors.white))
valueColor:new AlwaysStoppedAnimation<Color>(Colors.yellow),
像这样使用——>
CircularProgressIndicator (valueColor: AlwaysStoppedAnimation (Colors.grey [500]),)),