概述

#

AppBarThemeBottomAppBarThemeInputDecorationTheme 已重構,以符合 Flutter 的元件主題約定。增加了 AppBarThemeDataBottomAppBarThemeDataInputDecorationThemeData 來定義元件視覺屬性預設值的覆蓋。Flutter 的釋出版本將繼續對這些元件主題進行規範化,以在 material 庫中提供更一致的主題體驗。

遷移指南

#

ThemeData

  • appBarTheme 屬性的型別已從 AppBarTheme 更改為 AppBarThemeData
  • bottomAppBarTheme 屬性的型別已從 BottomAppBarTheme 更改為 BottomAppBarThemeData
  • inputDecorationTheme 屬性的型別已從 InputDecorationTheme 更改為 InputDecorationThemeData

元件主題 xTheme.of() 方法和 Theme.of().xTheme 的返回型別也已更改為 xThemeData

DatePickerThemeDataTimePickerThemeData 中,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