我试图通过点击按钮在我的扑动应用程序中显示CircularProgressIndicator
,但它不会呈现循环进度条,但是一旦我更改代码以使用LinearProgressBar
,进度条就没有任何问题。所以想知道我需要显示圆形加载指示器的任何特殊设置吗?
作品
if (_isFetching) {
return new Scaffold(
body: new Center(
child: new SizedBox(
width: 40.0,
height: 40.0,
child: const LinearProgressIndicator(backgroundColor: Colors.black)),
));
}
不工作
if (_isFetching) {
return new Scaffold(
body: new Center(
child: new SizedBox(
width: 40.0,
height: 40.0,
child: const CircularProgressIndicator(backgroundColor: Colors.black)),
));
}
你可以在这里参考docs。您正在使用backgroundColor属性,该属性仅定义指标的背景颜色而不是指标的类型。我正在使用null
作为Indeterminate类型。您可以使用valueColor
[doc]属性来更改指标的颜色。这是简单的代码,它工作正常。
if (_isFetching) {
return new Scaffold(
body: new Center(
child: new SizedBox(
width: 40.0,
height: 40.0,
child:
const CircularProgressIndicator(
value: null,
strokeWidth: 2.0,
)),
));
}
确保进度条值颜色与父窗口小部件背景颜色不同。试试这个:
if (_isFetching) {
return Scaffold(
body: Center(
child: SizedBox(
width: 40.0,
height: 40.0,
child: const CircularProgressIndicator(
backgroundColor: Colors.black,
valueColor: AlwaysStoppedAnimation<Color>(Colors.red))),
));
}