v3.3 版後移除的已棄用 API
摘要
#根據 Flutter 的 棄用政策,在 3.3 穩定版本之後達到生命週期結束的已棄用 API 已被移除。
所有受影響的 API 都已編譯到此主要來源中,以協助遷移。另提供一份快速參考表。
變更
#本節列出已棄用的項目,並依受影響的類別排序。
RenderUnconstrainedBox
#Flutter Fix 支援:否
RenderUnconstrainedBox
在 v2.1 版中已棄用。請改用 RenderConstraintsTransformBox
。
在兩個軸向均無約束的情況下,請將 ConstraintsTransformBox.unconstrained
提供給 constraintsTransform
。
如果先前設定了 RenderUnconstrainedBox.constrainedAxis
,請分別替換為
- 如果先前
constrainedAxis
為Axis.horizontal
,請將constraintsTransform
設定為ConstraintsTransformBox.widthUnconstrained
。 - 如果先前
constrainedAxis
為Axis.vertical
,請將constraintsTransform
設定為ConstraintsTransformBox.heightUnconstrained
。
此變更允許透過 ConstraintsTransformBox
引入更多類型的約束轉換。舊 API 的其他參數與新 API 相容。
遷移指南
遷移前的程式碼
// Unconstrained
final RenderUnconstrainedBox unconstrained = RenderUnconstrainedBox(
textDirection: TextDirection.ltr,
child: RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 200.0),
),
alignment: Alignment.center,
);
// Constrained in horizontal axis
final RenderUnconstrainedBox unconstrained = RenderUnconstrainedBox(
constrainedAxis: Axis.horizontal,
textDirection: TextDirection.ltr,
child: RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(width: 200.0, height: 200.0),
),
alignment: Alignment.center,
);
// Constrained in vertical axis
final RenderUnconstrainedBox unconstrained = RenderUnconstrainedBox(
constrainedAxis: Axis.vertical,
textDirection: TextDirection.ltr,
child: RenderFlex(
direction: Axis.vertical,
textDirection: TextDirection.ltr,
children: <RenderBox>[flexible],
),
alignment: Alignment.center,
);
遷移後的程式碼
// Unconstrained
final RenderConstraintsTransformBox unconstrained = RenderConstraintsTransformBox(
constraintsTransform: ConstraintsTransformBox.unconstrained,
textDirection: TextDirection.ltr,
child: RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 200.0),
),
alignment: Alignment.center,
);
// Constrained in horizontal axis
final RenderConstraintsTransformBox unconstrained = RenderConstraintsTransformBox(
constraintsTransform: ConstraintsTransformBox.widthUnconstrained,
textDirection: TextDirection.ltr,
child: RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(width: 200.0, height: 200.0),
),
alignment: Alignment.center,
);
// Constrained in vertical axis
final RenderConstraintsTransformBox unconstrained = RenderConstraintsTransformBox(
constraintsTransform: ConstraintsTransformBox.widthUnconstrained,
textDirection: TextDirection.ltr,
child: RenderFlex(
direction: Axis.vertical,
textDirection: TextDirection.ltr,
children: <RenderBox>[flexible],
),
alignment: Alignment.center,
);
參考資料
API 文件
相關 PR
DragAnchor
、Draggable.dragAnchor
& LongPressDraggable.dragAnchor
#Flutter Fix 支援:是
列舉 DragAnchor
,及其在 Draggable.dragAnchor
和 LongPressDraggable.dragAnchor
中的用法,已在 v2.1 中棄用。請改用 dragAnchorStrategy
。
當與其他小工具(例如 Stack
和 InteractiveViewer
)一起使用時,此變更可更準確地回饋可拖曳的小工具。
遷移指南
遷移前的程式碼
Draggable draggable = Draggable();
draggable = Draggable(dragAnchor: DragAnchor.child);
draggable = Draggable(dragAnchor: DragAnchor.pointer);
LongPressDraggable longPressDraggable = LongPressDraggable();
longPressDraggable = LongPressDraggable(dragAnchor: DragAnchor.child);
longPressDraggable = LongPressDraggable(dragAnchor: DragAnchor.pointer);
遷移後的程式碼
Draggable draggable = Draggable();
draggable = Draggable(dragAnchorStrategy: childDragAnchorStrategy);
draggable = Draggable(dragAnchorStrategy: pointerDragAnchorStrategy);
LongPressDraggable longPressDraggable = LongPressDraggable();
longPressDraggable = LongPressDraggable(dragAnchorStrategy: childDragAnchorStrategy);
longPressDraggable = LongPressDraggable(dragAnchorStrategy: pointerDragAnchorStrategy);
參考資料
API 文件
相關問題
相關 PR
ScrollBehavior.buildViewportChrome
#Flutter Fix 支援:是
方法 ScrollBehavior.buildViewportChrome
已在 v2.1 中棄用。
Scrollable
小工具使用此方法在適當的平台上預設套用捲動溢位指示器,例如 GlowingOverscrollIndicator
。隨著新增更多預設裝飾器,例如 Scrollbar
,每個都改為分割成個別的方法來取代 buildViewportChrome
。
這允許擴充類別僅覆寫特定的裝飾器,透過 buildScrollbar
或 buildOverscrollIndicator
,而不是需要重寫程式碼以維護其中一個或另一個。
遷移指南
遷移前的程式碼
final ScrollBehavior scrollBehavior = ScrollBehavior();
scrollBehavior.buildViewportChrome(context, child, axisDirection);
遷移後的程式碼
final ScrollBehavior scrollBehavior = ScrollBehavior();
scrollBehavior.buildOverscrollIndicator(context, child, axisDirection);
參考資料
設計文件
API 文件
相關問題
相關 PR
時間軸
#穩定版本:3.7
除非另有說明,否則本網站上的文件反映了 Flutter 的最新穩定版本。頁面上次更新於 2024-06-01。 檢視原始碼 或 回報問題。