已废弃的 API 在 v2.2 后移除
概述
#根据 Flutter 的弃用政策,在 2.2 稳定版发布后达到生命周期结束的已废弃 API 已被移除。
所有受影响的 API 都已汇编到此主要源中,以帮助进行迁移。速查表也已提供。
变更
#本节列出了按受影响类别的弃用内容。
InputDecoration
和 InputDecorationTheme
的 hasFloatingPlaceholder
#Flutter Fix 支持:是
hasFloatingPlaceholder
在 v1.13.2 中已废弃。请改用 floatingLabelBehavior
。如果 useFloatingPlaceholder
为 true,请替换为 FloatingLabelBehavior.auto
。如果 useFloatingPlaceholder
为 false,请替换为 FloatingLabelBehavior.never
。此更改允许指定超出原始二元选择的更多行为,增加了 FloatingLabelBehavior.always
作为额外的选项。
迁移指南
迁移前的代码
// InputDecoration
// Base constructor
InputDecoration(hasFloatingPlaceholder: true);
InputDecoration(hasFloatingPlaceholder: false);
// collapsed constructor
InputDecoration.collapsed(hasFloatingPlaceholder: true);
InputDecoration.collapsed(hasFloatingPlaceholder: false);
// Field access
inputDecoration.hasFloatingPlaceholder;
// InputDecorationTheme
// Base constructor
InputDecorationTheme(hasFloatingPlaceholder: true);
InputDecorationTheme(hasFloatingPlaceholder: false);
// Field access
inputDecorationTheme.hasFloatingPlaceholder;
// copyWith
inputDecorationTheme.copyWith(hasFloatingPlaceholder: false);
inputDecorationTheme.copyWith(hasFloatingPlaceholder: true);
迁移后的代码
// InputDecoration
// Base constructor
InputDecoration(floatingLabelBehavior: FloatingLabelBehavior.auto);
InputDecoration(floatingLabelBehavior: FloatingLabelBehavior.never);
// collapsed constructor
InputDecoration.collapsed(floatingLabelBehavior: FloatingLabelBehavior.auto);
InputDecoration.collapsed(floatingLabelBehavior: FloatingLabelBehavior.never);
// Field access
inputDecoration.floatingLabelBehavior;
// InputDecorationTheme
// Base constructor
InputDecorationTheme(floatingLabelBehavior: FloatingLabelBehavior.auto);
InputDecorationTheme(floatingLabelBehavior: FloatingLabelBehavior.never);
// Field access
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 |
---|---|
display4 | headline1 |
display3 | headline2 |
display2 | headline3 |
display1 | headline4 |
headline | headline5 |
title | headline6 |
subhead | subtitle1 |
body2 | bodyText1 |
body1 | bodyText2 |
subtitle | subtitle2 |
迁移指南
迁移前的代码
// TextTheme
// Base constructor
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,
);
// Getters
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;
迁移后的代码
// TextTheme
// Base constructor
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
s 反映 2018 年 Material Design 规范。对于前者,请使用 material2014
构造函数。
迁移指南
迁移前的代码
// Formerly returned 2014 TextStyle spec
Typography();
迁移后的代码
// Use 2018 TextStyle spec, either by default or explicitly.
Typography();
Typography.material2018();
// Use 2014 spec from former API
Typography.material2014();
参考资料
设计文档
API 文档
相关问题
相关 PR
时间线
#稳定版本:2.5