如何更改CircularProgressIndicator的颜色?

颜色的值是Animation< color >的实例,但我希望有一种更简单的方法来改变颜色,没有动画的麻烦。


当前回答

试试这个:

CircularProgressIndicator(
  color: Colors.yellow, // Change your color here
),

其他回答

解决问题的三种方法

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(),
)

使用progressIndicatorTheme允许为进度指示器定义一个主题。

ThemeData(
      progressIndicatorTheme: ProgressIndicatorThemeData(color: Colors.white),
    )
<com.google.android.material.progressindicator.CircularProgressIndicator app:indicatorColor="@color/primaryColor" />

试试这个:

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