如何更改CircularProgressIndicator的颜色?
颜色的值是Animation< color >的实例,但我希望有一种更简单的方法来改变颜色,没有动画的麻烦。
如何更改CircularProgressIndicator的颜色?
颜色的值是Animation< color >的实例,但我希望有一种更简单的方法来改变颜色,没有动画的麻烦。
当前回答
使用progressIndicatorTheme允许为进度指示器定义一个主题。
ThemeData(
progressIndicatorTheme: ProgressIndicatorThemeData(color: Colors.white),
)
其他回答
只需将此代码写入应用程序的主题数据
ThemeData(
progressIndicatorTheme: ProgressIndicatorThemeData(
color: Colors.grey.shade700,),)
对于单色集合,
CircularProgressIndicator(
valueColor:AlwaysStoppedAnimation<Color>(Colors.red),
);
适用于多种颜色变换/设置。
class MyApp extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyApp> with TickerProviderStateMixin {
AnimationController animationController;
@override
void dispose() {
// TODO: implement dispose
super.dispose();
animationController.dispose();
}
@override
void initState() {
super.initState();
animationController =
AnimationController(duration: new Duration(seconds: 2), vsync: this);
animationController.repeat();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Color Change CircularProgressIndicator"),
),
body: Center(
child: CircularProgressIndicator(
valueColor: animationController
.drive(ColorTween(begin: Colors.blueAccent, end: Colors.red)),
),
),
);
}
}
这招对我很管用:
CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(Colors.white))
主题是可以插入到小部件树中的任何位置的小部件。 它用自定义值覆盖当前主题 试试这个:
new Theme(
data: Theme.of(context).copyWith(accentColor: Colors.yellow),
child: new CircularProgressIndicator(),
);
参考:https://gitter.im/flutter/flutter?at=5a84cf9218f388e626a51c2d
像这样使用——>
CircularProgressIndicator (valueColor: AlwaysStoppedAnimation (Colors.grey [500]),)),