元件主題規範化更新
概述
#AppBarTheme、BottomAppBarTheme 和 InputDecorationTheme 已重構,以符合 Flutter 的元件主題約定。增加了 AppBarThemeData、BottomAppBarThemeData 和 InputDecorationThemeData 來定義元件視覺屬性預設值的覆蓋。Flutter 的釋出版本將繼續對這些元件主題進行規範化,以在 material 庫中提供更一致的主題體驗。
遷移指南
#在 ThemeData 中
appBarTheme屬性的型別已從AppBarTheme更改為AppBarThemeData。bottomAppBarTheme屬性的型別已從BottomAppBarTheme更改為BottomAppBarThemeData。inputDecorationTheme屬性的型別已從InputDecorationTheme更改為InputDecorationThemeData。
元件主題 xTheme.of() 方法和 Theme.of().xTheme 的返回型別也已更改為 xThemeData。
在 DatePickerThemeData 和 TimePickerThemeData 中,inputDecorationTheme 屬性的型別已從 InputDecorationTheme 更改為 InputDecorationThemeData。
遷移前的程式碼
dart
final AppBarTheme appBarTheme = Theme.of(context).appBarTheme;
final AppBarTheme appBarTheme = AppBarTheme.of(context);
final BottomAppBarTheme bottomAppBarTheme = Theme.of(context).bottomAppBarTheme;
final BottomAppBarTheme bottomAppBarTheme = BottomAppBarTheme.of(context);
final InputDecorationTheme inputDecorationTheme = Theme.of(context).inputDecorationTheme;
final InputDecorationTheme inputDecorationTheme = InputDecorationTheme.of(context);
final InputDecorationTheme inputDecorationTheme = Theme.of(context).datePickerTheme.inputDecorationTheme;
final InputDecorationTheme inputDecorationTheme = Theme.of(context).timePickerTheme.inputDecorationTheme;dart
final ThemeData theme = ThemeData(
appBarTheme: AppBarTheme(),
bottomAppBarTheme: BottomAppBarTheme(),
inputDecorationTheme: InputDecorationTheme(),
);
final ThemeData theme = ThemeData().copyWith(
appBarTheme: AppBarTheme(),
bottomAppBarTheme: BottomAppBarTheme(),
inputDecorationTheme: InputDecorationTheme(),
);
const DatePickerThemeData datePickerTheme = DatePickerThemeData(inputDecorationTheme: InputDecorationTheme());
const TimePickerThemeData timePickerTheme = TimePickerThemeData(inputDecorationTheme: InputDecorationTheme());遷移後的程式碼
dart
final AppBarThemeData appBarTheme = Theme.of(context).appBarTheme;
final AppBarThemeData appBarTheme = AppBarTheme.of(context);
final BottomAppBarThemeData bottomAppBarTheme = Theme.of(context).bottomAppBarTheme;
final BottomAppBarThemeData bottomAppBarTheme = BottomAppBarTheme.of(context);
final InputDecorationThemeData inputDecorationTheme = Theme.of(context).inputDecorationTheme;
final InputDecorationThemeData inputDecorationTheme = InputDecorationTheme.of(context);
final InputDecorationThemeData inputDecorationTheme = Theme.of(context).datePickerTheme.inputDecorationTheme;
final InputDecorationThemeData inputDecorationTheme = Theme.of(context).timePickerTheme.inputDecorationTheme;dart
final ThemeData theme = ThemeData(
appBarTheme: AppBarThemeData(),
bottomAppBarTheme: BottomAppBarThemeData(),
inputDecorationTheme: InputDecorationThemeData(),
);
final ThemeData theme = ThemeData().copyWith(
appBarTheme: AppBarThemeData(),
bottomAppBarTheme: BottomAppBarThemeData(),
inputDecorationTheme: InputDecorationThemeData(),
);
const DatePickerThemeData datePickerTheme = DatePickerThemeData(inputDecorationTheme: InputDecorationThemeData());
const TimePickerThemeData timePickerTheme = TimePickerThemeData(inputDecorationTheme: InputDecorationThemeData());時間線
#包含在版本中:3.33.0-1.0.pre 至 3.35.0-0.0.pre
穩定版釋出:3.35
參考資料
#API 文件
相關 PR