Skip to main content

2.2 版本后移除的已弃用 API

摘要

#

根据 Flutter 的弃用策略,在 2.2 稳定版本之后达到生命周期结束的已弃用 API 已被移除。

所有受影响的 API 都已编译到此主要资源中,以帮助迁移。还有一个快速参考表 可供使用。

变更

#

本节列出了按受影响的类列出的弃用项。

InputDecorationInputDecorationThemehasFloatingPlaceholder

#

Flutter Fix 支持:是

hasFloatingPlaceholder 在 v1.13.2 中已弃用。 请改用 floatingLabelBehavior。 如果 useFloatingPlaceholder 为 true,则替换为 FloatingLabelBehavior.auto。 如果 useFloatingPlaceholder 为 false,则替换为 FloatingLabelBehavior.never。 此更改允许指定超出原始二元选择的更多行为,并添加 FloatingLabelBehavior.always 作为附加选项。

迁移指南

迁移前的代码:

dart
// InputDecoration
// 基本构造函数
InputDecoration(hasFloatingPlaceholder: true);
InputDecoration(hasFloatingPlaceholder: false);

// 折叠式构造函数
InputDecoration.collapsed(hasFloatingPlaceholder: true);
InputDecoration.collapsed(hasFloatingPlaceholder: false);

// 字段访问
inputDecoration.hasFloatingPlaceholder;

// InputDecorationTheme
// 基本构造函数
InputDecorationTheme(hasFloatingPlaceholder: true);
InputDecorationTheme(hasFloatingPlaceholder: false);

// 字段访问
inputDecorationTheme.hasFloatingPlaceholder;

// copyWith
inputDecorationTheme.copyWith(hasFloatingPlaceholder: false);
inputDecorationTheme.copyWith(hasFloatingPlaceholder: true);

迁移后的代码:

dart
// InputDecoration
// 基本构造函数
InputDecoration(floatingLabelBehavior: FloatingLabelBehavior.auto);
InputDecoration(floatingLabelBehavior: FloatingLabelBehavior.never);

// 折叠式构造函数
InputDecoration.collapsed(floatingLabelBehavior: FloatingLabelBehavior.auto);
InputDecoration.collapsed(floatingLabelBehavior: FloatingLabelBehavior.never);

// 字段访问
inputDecoration.floatingLabelBehavior;

// InputDecorationTheme
// 基本构造函数
InputDecorationTheme(floatingLabelBehavior: FloatingLabelBehavior.auto);
InputDecorationTheme(floatingLabelBehavior: FloatingLabelBehavior.never);

// 字段访问
inputDecorationTheme.floatingLabelBehavior;

// copyWith
inputDecorationTheme.copyWith(floatingLabelBehavior: FloatingLabelBehavior.never);
inputDecorationTheme.copyWith(floatingLabelBehavior: FloatingLabelBehavior.auto);

参考

API 文档:

相关问题:

相关 PR:


TextTheme

#

Flutter Fix 支持:是

TextTheme 的几个 TextStyle 属性在 v1.13.8 中已弃用。它们与新 API 中相应的替换项一起列在下表中。

已弃用新 API
display4headline1
display3headline2
display2headline3
display1headline4
headlineheadline5
titleheadline6
subheadsubtitle1
body2bodyText1
body1bodyText2
subtitlesubtitle2

迁移指南

迁移前的代码:

dart
// TextTheme
// 基本构造函数
TextTheme(
  display4: displayStyle4,
  display3: displayStyle3,
  display2: displayStyle2,
  display1: displayStyle1,
  headline: headlineStyle,
  title: titleStyle,
  subhead: subheadStyle,
  body2: body2Style,
  body1: body1Style,
  caption: captionStyle,
  button: buttonStyle,
  subtitle: subtitleStyle,
  overline: overlineStyle,
);

// copyWith
TextTheme.copyWith(
  display4: displayStyle4,
  display3: displayStyle3,
  display2: displayStyle2,
  display1: displayStyle1,
  headline: headlineStyle,
  title: titleStyle,
  subhead: subheadStyle,
  body2: body2Style,
  body1: body1Style,
  caption: captionStyle,
  button: buttonStyle,
  subtitle: subtitleStyle,
  overline: overlineStyle,
);

// Getter
TextStyle style;
style = textTheme.display4;
style = textTheme.display3;
style = textTheme.display2;
style = textTheme.display1;
style = textTheme.headline;
style = textTheme.title;
style = textTheme.subhead;
style = textTheme.body2;
style = textTheme.body1;
style = textTheme.caption;
style = textTheme.button;
style = textTheme.subtitle;
style = textTheme.overline;

迁移后的代码:

dart
// TextTheme
// 基本构造函数
TextTheme(
  headline1: displayStyle4,
  headline2: displayStyle3,
  headline3: displayStyle2,
  headline4: displayStyle1,
  headline5: headlineStyle,
  headline6: titleStyle,
  subtitle1: subheadStyle,
  bodyText1: body2Style,
  bodyText2: body1Style,
  caption: captionStyle,
  button: buttonStyle,
  subtitle2: subtitleStyle,
  overline: overlineStyle,
);

TextTheme.copyWith(
  headline1: displayStyle4,
  headline2: displayStyle3,
  headline3: displayStyle2,
  headline4: displayStyle1,
  headline5: headlineStyle,
  headline6: titleStyle,
  subtitle1: subheadStyle,
  bodyText1: body2Style,
  bodyText2: body1Style,
  caption: captionStyle,
  button: buttonStyle,
  subtitle2: subtitleStyle,
  overline: overlineStyle,
);

TextStyle style;
style = textTheme.headline1;
style = textTheme.headline2;
style = textTheme.headline3;
style = textTheme.headline4;
style = textTheme.headline5;
style = textTheme.headline6;
style = textTheme.subtitle1;
style = textTheme.bodyText1;
style = textTheme.bodyText2;
style = textTheme.caption;
style = textTheme.button;
style = textTheme.subtitle2;
style = textTheme.overline;

参考

设计文档:

API 文档:

相关问题:

相关 PR:


默认 Typography

#

Flutter Fix 支持:否

默认 Typography 在 v1.13.8 中已弃用。 之前的默认值返回 2014 年 Material Design 规范的文本样式。 这现在将导致 TextStyle 反映 2018 年 Material Design 规范。 对于前者,请使用 material2014 构造函数。

迁移指南

迁移前的代码:

dart
// 以前返回 2014 TextStyle 规范
Typography();

迁移后的代码:

dart
// 使用 2018 TextStyle 规范,默认或显式方式均可。
Typography();
Typography.material2018();

// 使用前 API 中的 2014 规范
Typography.material2014();

参考

设计文档:

API 文档:

相关问题:

相关 PR:


时间线

#

稳定版本:2.5