元件主題正規化
`CardTheme`、`DialogTheme` 和 `TabBarTheme` 已正規化,以遵循 Flutter 在 Material 函式庫中對元件主題 (Component Theme) 的慣例。
摘要
#
CardTheme、DialogTheme 和 TabBarTheme 已重構,以符合 Flutter 對元件主題的慣例。
CardThemeData、DialogThemeData 和 TabBarThemeData
已新增,用於定義元件視覺屬性的預設值覆寫。
Flutter 的發行版本會持續對這類元件主題進行正規化,以在 Material 函式庫中帶來更一致的主題化體驗。
遷移指南
#在 ThemeData 中:
cardTheme屬性的型別已從CardTheme變更為CardThemeData。dialogTheme屬性的型別已從DialogTheme變更為DialogThemeData。tabBarTheme屬性的型別已從TabBarTheme變更為TabBarThemeData。
元件主題 xTheme.of() 方法與 Theme.of().xTheme 的回傳型別也已相應變更為 xThemeData。
遷移前的程式碼:
final CardTheme cardTheme = Theme.of(context).cardTheme;
final CardTheme cardTheme = CardTheme.of(context);
final DialogTheme dialogTheme = Theme.of(context).dialogTheme;
final DialogTheme dialogTheme = DialogTheme.of(context);
final TabBarTheme tabBarTheme = Theme.of(context).tabBarTheme;
final TabBarTheme tabBarTheme = TabBarTheme.of(context);
遷移後的程式碼:
final CardThemeData cardTheme = Theme.of(context).cardTheme;
final CardThemeData cardTheme = CardTheme.of(context);
final DialogThemeData dialogTheme = Theme.of(context).dialogTheme;
final DialogThemeData dialogTheme = DialogTheme.of(context);
final TabBarThemeData tabBarTheme = Theme.of(context).tabBarTheme;
final TabBarThemeData tabBarTheme = TabBarTheme.of(context);
時程
#
合併於版本:3.27.0-0.0.pre
穩定版本:3.27
參考資料
#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.