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。 檢視原始碼 或 回報問題。