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