v2.2 后移除已弃用的 API
概述
#根据 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
反映 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