简体   繁体   English

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

[英]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.

相关问题 更改 Flutter alertDialog 中操作部分的背景颜色 - Change background color for the action section in Flutter alertDialog Flutter | 如何将我的 FloatingActionButton 背景颜色更改为透明? - Flutter | How can I change my FloatingActionButton background color to transparent? Flutter - 如何更改 LicensePage 的背景颜色? - Flutter - How can I change the background color of LicensePage? 如何更改 flutter 中文本按钮的背景颜色? - How can I change the background color of a textbutton in flutter? 如何在 Flutter 的 AlertDialog 上设置背景图像? - How can I set a background image on an AlertDialog in Flutter? Flutter 使用 ListView.Builder:如何在我选择的所有项目上仅更改一项的背景颜色 - Flutter Using ListView.Builder: how can i change background color of only one item on all items with i selected it 如何在 Flutter 中使用 CustomPainter 更改绘制的 object 的颜色? - How can I change the color of a drawn object using CustomPainter in Flutter? 我可以在 flutter 中永久更改提升按钮的背景颜色吗? - Can I change the background color of elevated button permanently in flutter? 如何更改 CupertinoDatePicker 的背景颜色 - How can i change the background color of CupertinoDatePicker 如何在 flutter 的 alertDialog 中使用 checkboxlisttile? - How can I use checkboxlisttile in alertDialog in flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM