如何更改CircularProgressIndicator的颜色?
颜色的值是Animation< color >的实例,但我希望有一种更简单的方法来改变颜色,没有动画的麻烦。
如何更改CircularProgressIndicator的颜色?
颜色的值是Animation< color >的实例,但我希望有一种更简单的方法来改变颜色,没有动画的麻烦。
当前回答
如果你想全局更改,在最新版本的flutter中,你应该更改colorScheme:
void main() => runApp(
MaterialApp(
title: 'App',
home: Home(),
theme: ThemeData(
colorScheme: ColorScheme(
primary: Colors.red,
// You should set other properties too
)
),
),
);
其他回答
<com.google.android.material.progressindicator.CircularProgressIndicator app:indicatorColor="@color/primaryColor" />
主题是可以插入到小部件树中的任何位置的小部件。 它用自定义值覆盖当前主题 试试这个:
new Theme(
data: Theme.of(context).copyWith(accentColor: Colors.yellow),
child: new CircularProgressIndicator(),
);
参考:https://gitter.im/flutter/flutter?at=5a84cf9218f388e626a51c2d
使用progressIndicatorTheme允许为进度指示器定义一个主题。
ThemeData(
progressIndicatorTheme: ProgressIndicatorThemeData(color: Colors.white),
)
如果你想全局更改,在最新版本的flutter中,你应该更改colorScheme:
void main() => runApp(
MaterialApp(
title: 'App',
home: Home(),
theme: ThemeData(
colorScheme: ColorScheme(
primary: Colors.red,
// You should set other properties too
)
),
),
);
可以使用accentColor作为widget的前景色。它可以改变任何前景小部件的颜色,包括circularprogressbar。
void main() => runApp(
MaterialApp(
title: 'Demo App',
home: MainClass(),
theme: ThemeData(accentColor: Colors.black),
),
);