组件主题规范化更新
概述
#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
稳定版本:尚未发布
参考资料
#API 文档
相关 PR