Skip to main content

组件主题规范化

摘要

#

CardThemeDialogThemeTabBarTheme 已重构以符合 Flutter 的组件主题约定。 添加了 CardThemeDataDialogThemeDataTabBarThemeData 来定义组件视觉属性默认值的覆盖。 Flutter 的版本继续规范化此类组件主题,以便在 Material 库中获得更一致的主题体验。

迁移指南

#

ThemeData 中:

  • cardTheme 属性的类型已从 CardTheme 更改为 CardThemeData
  • dialogTheme 属性的类型已从 DialogTheme 更改为 DialogThemeData
  • tabBarTheme 属性的类型已从 TabBarTheme 更改为 TabBarThemeData

组件主题 xTheme.of() 方法和 Theme.of().xTheme 的返回类型也相应地更改为 xThemeData

迁移前的代码:

dart
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);

迁移后的代码:

dart
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: