Flutter 使用主题小部件设置CircularProgressIndicator的背景色
如何使用颤振主题小部件设置CircularProgressIndicator的背景色Flutter 使用主题小部件设置CircularProgressIndicator的背景色,flutter,Flutter,如何使用颤振主题小部件设置CircularProgressIndicator的背景色 我可以在创建CircularProgressIndicator时将backgroundColor作为参数传递,但我希望在围绕Scaffold小部件的主题中这样做。主题数据中的哪个值用于确定此小部件的背景颜色?如果要设置背景颜色和进度圈颜色,建议使用以下值: circularProgress(){ 返回容器( 颜色:颜色,白色, 对齐:对齐.center, 填充:仅限边缘设置(顶部:12.0), 子对象:循环压缩
我可以在创建CircularProgressIndicator时将backgroundColor作为参数传递,但我希望在围绕Scaffold小部件的主题中这样做。主题数据中的哪个值用于确定此小部件的背景颜色?如果要设置背景颜色和进度圈颜色,建议使用以下值:
circularProgress(){
返回容器(
颜色:颜色,白色,
对齐:对齐.center,
填充:仅限边缘设置(顶部:12.0),
子对象:循环压缩机指示器(
valueColor:AlwaysStoppedAnimation(Colors.redAccent),
),
);
}
由于flatter中的一个错误,您似乎无法使用flatter主题数据更改CircularProgressIndicator
的背景色
我在GitHub上发布了一个问题:
根据文档(),默认情况下,CircularProgressIndicator
的backgroundColor
应该是当前主题的ThemeData.backgroundColor
虽然valueColor
(ThemeData.accentColor
默认情况下)是这种情况,但它不适用于backgroundColor
我认为问题在于\u buildMaterialIndicator
方法,如果backgroundColor设置为小部件。backgroundColor
而不是\u getBackgroundColor(上下文)
复制问题的完整源代码:
导入“包装:颤振/材料.省道”;
void main(){
runApp(
材料聚丙烯(
debugShowCheckedModeBanner:false,
标题:“颤振演示”,
主页:主页(),
),
);
}
类主页扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:中(
子:列(
mainAxisAlignment:mainAxisAlignment.center,
mainAxisSize:mainAxisSize.min,
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
Text('默认值:'),
CircularProgressIndicator(),
const SizedBox(高度:16.0),
文本('背景色:'),
循环压缩机指示器(
背景颜色:Colors.amber.shade300,
),
const SizedBox(高度:16.0),
文本('主题:'),
主题(
数据:Theme.of(context).copyWith(
accentColor:Colors.green.shade300,
画布颜色:Colors.red.shade300,
背景颜色:Colors.amber.shade300,
),
子项:CircularProgressIndicator(背景色:null),
),
],
),
),
);
}
}
非常感谢。我试着改变主题数据中的很多值,但都没有成功。我希望它将在以后的版本中修复。这将节省我大量的体力劳动,并保持代码可读性
Widget _buildMaterialIndicator(BuildContext context, double headValue, double tailValue, double offsetValue, double rotationValue) {
return widget._buildSemanticsWrapper(
context: context,
child: Container(
constraints: const BoxConstraints(
minWidth: _kMinCircularProgressIndicatorSize,
minHeight: _kMinCircularProgressIndicatorSize,
),
child: CustomPaint(
painter: _CircularProgressIndicatorPainter(
backgroundColor: widget.backgroundColor,
valueColor: widget._getValueColor(context),
value: widget.value, // may be null
headValue: headValue, // remaining arguments are ignored if widget.value is not null
tailValue: tailValue,
offsetValue: offsetValue,
rotationValue: rotationValue,
strokeWidth: widget.strokeWidth,
),
),
),
);
}