简体   繁体   中英

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?

You can use Container as the title .

There's a titlePadding property for AlertDialog . If title isn't null, the default value is 24. therefore you need to explicitly supply it with 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 .

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),
 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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