棄用 ThemeData.dialogBackgroundColor,改用 DialogThemeData.backgroundColor
`ThemeData.dialogBackgroundColor` 參數已被 `DialogThemeData.backgroundColor` 取代。
摘要
#
ThemeData.dialogBackgroundColor
參數已被棄用,建議改用
DialogThemeData.backgroundColor
參數。
背景說明
#
Dialog 與 AlertDialog
元件 (Widget) 的預設值可以透過像
DialogThemeData
這樣的元件專屬主題(component-specific theme)來覆寫。
過去,會使用 ThemeData.dialogBackgroundColor 參數來覆寫對話框的預設背景顏色,
但這個作法已因 DialogThemeData
而變得多餘。
變更說明
#
ThemeData.dialogBackgroundColor
已被棄用,建議改用元件專屬主題
(component-specific theme)。如需覆寫預設背景顏色,請使用 DialogThemeData。
遷移指南
#
如需覆寫對話框的預設背景顏色,請將 ThemeData.dialogBackgroundColor
替換為 DialogThemeData.backgroundColor。
遷移前的程式碼:
theme: ThemeData(
dialogBackgroundColor: Colors.orange,
),
遷移後的程式碼:
theme: ThemeData(
dialogTheme: const DialogThemeData(backgroundColor: Colors.orange),
),
時程
#
合併於版本:3.28.0-0.1.pre
穩定版釋出:3.29
參考資料
#API 文件:
相關議題:
相關 PR:
Unless stated otherwise, the documentation on this site reflects Flutter 3.44.0. Page last updated on 2026-06-14. View source or report an issue.