繁体   English   中英

如何使用 flutter 中的 alertDialog 更改 header 的背景颜色?

[英]how can I change the background color of the header using an alertDialog in flutter?

目前只有文字只用以下代码绘制

在此处输入图像描述

AlertDialog(
   shape: RoundedRectangleBorder(
   borderRadius: BorderRadius.circular(20.0)),
   title: Text(
     'Error',
     style: TextStyle(backgroundColor: STYLES.styles["success"]),
   )
   .
   .
   .

我想用一种颜色绘制 alertDialog 的 header,我该怎么做?

您可以使用 Container 作为title

AlertDialog有一个titlePadding属性。 如果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),
)

您可以将标题包装在Container中并将其与center对齐。

试试这样的..

 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM