[英]how can I change the background color of the header using an alertDialog in flutter?
currently only the text is only painted with the following code目前只有文字只用以下代码绘制
AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
title: Text(
'Error',
style: TextStyle(backgroundColor: STYLES.styles["success"]),
)
.
.
.
I would like to paint the header of the alertDialog in one color, how can I do it?我想用一种颜色绘制 alertDialog 的 header,我该怎么做?
You can use Container as the title
.您可以使用 Container 作为title
。
There's a titlePadding
property for AlertDialog
. AlertDialog
有一个titlePadding
属性。 If title
isn't null, the default value is 24. therefore you need to explicitly supply it with 0.如果title
不是 null,则默认值为 24。因此您需要显式地为其提供 0。
AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
title: Container(
color: Colors.red,
child: Text('Error'),
),
titlePadding: const EdgeInsets.all(0),
)
You can wrap the title inside a Container
and align it with center
.您可以将标题包装在Container
中并将其与center
对齐。
Try something like this..试试这样的..
AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
title: Container(
color: Colors.orange,
child: Center(
child: Text("Error"),
)),
titlePadding: const EdgeInsets.all(0),
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.