簡體   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