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
除非另有说明,否则本网站上的文档反映了 Flutter 的最新稳定版本。页面上次更新于 2024-06-01。 查看源代码 或 报告问题。