v2.10 後移除的已棄用 API
概述
#根據 Flutter 的棄用策略,在 2.10 穩定版釋出後達到生命週期結束的已棄用 API 已被移除。
所有受影響的 API 都已編譯到此主源中,以幫助遷移。同時提供了快速參考表。
變更
#本節按受影響的類列出了棄用項。
TextField & 相關類的 maxLengthEnforced
#Flutter Fix 支援:是
maxLengthEnforced 在 v1.25 中被棄用。
請改用 maxLengthEnforcement。將 maxLengthEnforced 為 true 的地方替換為 MaxLengthEnforcement.enforce。將 maxLengthEnforced 為 false 的地方替換為 MaxLengthEnforcement.none。此更改允許指定比原始二元選擇更多的行為,並增加了 MaxLengthEnforcement.truncateAfterCompositionEnds 作為附加選項。
以下類均具有相同的 API 更改
TextFieldTextFormFieldCupertinoTextField
遷移指南
遷移前的程式碼
const TextField textField = TextField(maxLengthEnforced: true);
const TextField textField = TextField(maxLengthEnforced: false);
final lengthEnforced = textField.maxLengthEnforced;
const TextFormField textFormField = TextFormField(maxLengthEnforced: true);
const TextFormField textFormField = TextFormField(maxLengthEnforced: false);
final lengthEnforced = textFormField.maxLengthEnforced;
const CupertinoTextField cupertinoTextField = CupertinoTextField(maxLengthEnforced: true);
const CupertinoTextField cupertinoTextField = CupertinoTextField(maxLengthEnforced: false);
final lengthEnforced = cupertinoTextField.maxLengthEnforced;遷移後的程式碼
const TextField textField = TextField(maxLengthEnforcement: MaxLengthEnforcement.enforce);
const TextField textField = TextField(maxLengthEnforcement: MaxLengthEnforcement.none);
final lengthEnforced = textField.maxLengthEnforcement;
const TextFormField textFormField = TextFormField(maxLengthEnforcement: MaxLengthEnforcement.enforce);
const TextFormField textFormField = TextFormField(maxLengthEnforcement: MaxLengthEnforcement.none);
final lengthEnforced = textFormField.maxLengthEnforcement;
const CupertinoTextField cupertinoTextField = CupertinoTextField(maxLengthEnforcement: MaxLengthEnforcement.enforce);
const CupertinoTextField cupertinoTextField = CupertinoTextField(maxLengthEnforcement: MaxLengthEnforcement.none);
final lengthEnforced = cupertinoTextField.maxLengthEnforcement;參考資料
API 文件
相關問題
相關 PR
VelocityTracker 建構函式
#Flutter Fix 支援:是
VelocityTracker 的預設建構函式在 v1.22 中被棄用。
應改用 VelocityTracker.withKind()。這允許為跟蹤器指定 PointerDeviceKind。之前 VelocityTracker.kind 的預設值是 PointerDeviceKind.touch。
遷移指南
遷移前的程式碼
final VelocityTracker tracker = VelocityTracker();遷移後的程式碼
final VelocityTracker tracker = VelocityTracker.withKind(PointerDeviceKind.touch);參考資料
API 文件
相關 PR
DayPicker & MonthPicker
#Flutter Fix 支援:否
DayPicker 和 MonthPicker 小部件首先在 v1.15 中被棄用,然後在 v1.26 中擴充套件。
它們已被一個全面的小部件 CalendarDatePicker 取代。
這些小部件曾使用 showDatePicker 方法顯示。該方法已遷移為在此版本之前呈現新的 CalendarDatePicker,因此它們的最終移除應該不需要進一步的操作。
參考資料
設計文件
API 文件
相關問題
相關 PR
FlatButton, RaisedButton, & OutlineButton
#Flutter Fix 支援:否
FlatButton、RaisedButton 和 OutlineButton 小部件首先在 v1.20 中被棄用,然後在 v1.26 中擴充套件。
它們已被新的按鈕 TextButton、ElevatedButton 和 OutlinedButton 取代。這些新小部件還使用新的關聯主題,而不是通用的 ButtonTheme。
| 舊小部件 | 舊主題 | 新小部件 | 新主題 |
|---|---|---|---|
FlatButton | ButtonTheme | 文字按鈕 | TextButtonTheme |
RaisedButton | ButtonTheme | 凸起按鈕 | ElevatedButtonTheme |
OutlineButton | ButtonTheme | OutlinedButton | OutlinedButtonTheme |
遷移指南
遷移前的程式碼
FlatButton(
onPressed: onPressed,
child: Text('Button'),
// ...
);
RaisedButton(
onPressed: onPressed,
child: Text('Button'),
// ...
);
OutlineButton(
onPressed: onPressed,
child: Text('Button'),
// ...
);遷移後的程式碼
TextButton(
onPressed: onPressed,
child: Text('Button'),
// ...
);
ElevatedButton(
onPressed: onPressed,
child: Text('Button'),
// ...
);
OutlinedButton(
onPressed: onPressed,
child: Text('Button'),
// ...
);參考資料
設計文件
API 文件
ButtonStyleButtonStyleButton凸起按鈕ElevatedButtonThemeElevatedButtonThemeDataOutlinedButtonOutlinedButtonThemeOutlinedButtonThemeData文字按鈕TextButtonThemeTextButtonThemeData
相關 PR
Scaffold SnackBar 方法
#Flutter Fix 支援:否
以下 Scaffold SnackBar 方法在 v1.23 中被棄用。
showSnackBarremoveCurrentSnackBarhideCurrentSnackBar
應改用 ScaffoldMessenger 的同名方法。每個 MaterialApp 中都已建立了一個預設的 ScaffoldMessenger。
遷移指南
遷移前的程式碼
Scaffold.of(context).showSnackBar(mySnackBar);
Scaffold.of(context).removeCurrentSnackBar(mySnackBar);
Scaffold.of(context).hideCurrentSnackBar(mySnackBar);遷移後的程式碼
ScaffoldMessenger.of(context).showSnackBar(mySnackBar);
ScaffoldMessenger.of(context).removeCurrentSnackBar(mySnackBar);
ScaffoldMessenger.of(context).hideCurrentSnackBar(mySnackBar);參考資料
設計文件
影片內容
API 文件
相關問題
相關 PR
RectangularSliderTrackShape.disabledThumbGapWidth
#Flutter Fix 支援:是
RectangularSliderTrackShape.disabledThumbGapWidth 首先在 v1.5 中被棄用,然後在 v1.26 中擴充套件。
框架不再使用此屬性,因為停用時滑塊拇指的動畫不再發生。
遷移指南
遷移前的程式碼
RectangularSliderTrackShape(disabledThumbGapWidth: 2.0);遷移後的程式碼
RectangularSliderTrackShape();參考資料
API 文件
相關 PR
ThemeData 的文字選擇到 TextSelectionThemeData
#Flutter Fix 支援:是
以下 ThemeData 成員首先在 v1.23 中被棄用,然後在 v1.26 中擴充套件。
useTextSelectionThemetextSelectionColorcursorColortextSelectionHandleColor
應將它們替換為更全面的 TextSelectionThemeData,後者現在本身就在 ThemeData 中指定。
useTextSelectionTheme 標誌曾用作區分兩個 API 的臨時遷移標誌,現在可以將其移除。
遷移指南
遷移前的程式碼
ThemeData(
useTextSelectionTheme: false,
textSelectionColor: Colors.blue,
cursorColor: Colors.green,
textSelectionHandleColor: Colors.red,
);遷移後的程式碼
ThemeData(
textSelectionTheme: TextSelectionThemeData(
selectionColor: Colors.blue,
cursorColor: Colors.green,
selectionHandleColor: Colors.red,
),
);參考資料
設計文件
API 文件
相關問題
相關 PR
RenderEditable.onSelectionChanged 到 TextSelectionDelegate.textEditingValue
#Flutter Fix 支援:否
RenderEditable.onSelectionChanged 和 TextSelectionDelegate.textEditingValue 在 v1.26 中被棄用。
不要呼叫其中一個或兩個方法,而是呼叫 TextSelectionDelegate.userUpdateTextEditingValue。這修復了一個錯誤,即 TextInputFormatter 會收到錯誤的選區值。
遷移指南
遷移前的程式碼
renderEditable.onSelectionChanged(selection, renderObject, cause);
textSelectionDelegate.textEditingValue = value;遷移後的程式碼
textSelectionDelegate.userUpdateTextEditingValue(value, cause);參考資料
API 文件
相關問題
- 已解決#75505
相關 PR
Stack.overflow
#Flutter Fix 支援:是
Stack.overflow 以及 Overflow 列舉在 v1.22 中被棄用。
替換項是 Stack.clipBehavior,這是作為統一框架剪裁行為和語義的一部分進行的更改。將 Overflow.visible 的使用替換為 Clip.none。將 Overflow.clip 的使用替換為 Clip.hardEdge。
遷移指南
遷移前的程式碼
const Stack stack = Stack(overflow: Overflow.visible);
const Stack stack = Stack(overflow: Overflow.clip);遷移後的程式碼
const Stack stack = Stack(clipBehavior: Clip.none);
const Stack stack = Stack(clipBehavior: Clip.hardEdge);參考資料
API 文件
相關問題
- 已解決#66030
相關 PR
UpdateLiveRegionEvent
#Flutter Fix 支援:否
SemanticsEvent UpdateLiveRegionEvent 首先在 v1.12 中被棄用,然後在 v1.26 中擴充套件。
框架從未實現過此功能,應刪除所有引用。
參考資料
API 文件
相關 PR
RenderObjectElement 方法
#Flutter Fix 支援:是
以下 RenderObjectElement 方法在 v1.21 中被棄用。
insertChildRenderObjectmoveChildRenderObjectremoveChildRenderObject
這些方法分別被以下方法取代:
insertRenderObjectChildmoveRenderObjectChildremoveRenderObjectChild
這些更改是作為軟破壞性棄用來進行的,目的是更改函式簽名。
遷移指南
遷移前的程式碼
element.insertChildRenderObject(child, slot);
element.moveChildRenderObject(child, slot);
element.removeChildRenderObject(child);遷移後的程式碼
element.insertRenderObjectChild(child, slot);
element.moveRenderObjectChild(child, oldSlot, newSlot);
element.removeRenderObjectChild(child, slot);參考資料
API 文件
相關問題
相關 PR
時間線
#穩定版本:3.0.0