v1.22 后移除的已弃用 API
概述
#根据 Flutter 的弃用策略,在 1.22 稳定版发布后生命周期结束的已弃用 API 已被移除。这是 Flutter 首次移除已弃用 API,其中一些弃用甚至早于我们的迁移指南策略。
所有受影响的 API 都已整理到这个主要源文件中,以协助迁移。您还可以找到一个快速参考表。
关于 Flutter 弃用策略的更多背景信息,请参阅设计文档和文章。
变更
#本节列出了按受影响类别的弃用内容。
CupertinoDialog
#由修复工具支持:仅 IDE 修复。
CupertinoDialog 在 v0.2.3 中已被弃用。请改用 CupertinoAlertDialog 或 CupertinoPopupSurface。
迁移指南
CupertinoAlertDialog
迁移前的代码
CupertinoDialog(child: myWidget);迁移后的代码
CupertinoAlertDialog(content: myWidget);CupertinoPopupSurface
迁移前的代码
CupertinoDialog(child: myWidget);迁移后的代码
CupertinoPopupSurface(child: myWidget);参考资料
API 文档
相关问题
相关 PR
Cupertino 导航栏的 actionsForegroundColor
#由修复工具支持:否
CupertinoNavigationBar.actionsForegroundColor 和 CupertinoSliverNavigationBar.actionsForegroundColor 在 v1.1.2 中已被弃用。现在可以通过设置 CupertinoTheme 中的 primaryColor 来实现此功能。要访问 primaryColor,请调用 CupertinoTheme.of(context).primaryColor。
迁移指南
迁移前的代码
CupertinoNavigationBar(
actionsForegroundColor: CupertinoColors.systemBlue,
);
CupertinoSliverNavigationBar(
actionsForegroundColor: CupertinoColors.systemBlue,
);迁移后的代码
CupertinoTheme(
data: CupertinoThemeData(
primaryColor: CupertinoColors.systemBlue
),
child: ...
);
// To access the color from the `CupertinoTheme`
CupertinoTheme.of(context).primaryColor;参考资料
API 文档
相关问题
相关 PR
CupertinoTextThemeData.brightness
#由修复工具支持:是
CupertinoTextThemeData.brightness 在 v1.10.14 中已被弃用。此字段在弃用时已失效。该参数没有替代方案,应移除相关引用。
迁移指南
迁移前的代码
const CupertinoTextThemeData themeData = CupertinoTextThemeData(brightness: Brightness.dark);
themeData.copyWith(brightness: Brightness.light);迁移后的代码
const CupertinoTextThemeData themeData = CupertinoTextThemeData();
themeData.copyWith();参考资料
API 文档
相关问题
相关 PR
由 fromHoverEvent 构建的 Pointer 事件
#由修复工具支持:是
PointerEnterEvent 和 PointerExitEvent 的 fromHoverEvent 构造函数在 v1.4.3 中已被弃用。应改用 fromMouseEvent 构造函数。
迁移指南
迁移前的代码
final PointerEnterEvent enterEvent = PointerEnterEvent.fromHoverEvent(PointerHoverEvent());
final PointerExitEvent exitEvent = PointerExitEvent.fromHoverEvent(PointerHoverEvent());迁移后的代码
final PointerEnterEvent enterEvent = PointerEnterEvent.fromMouseEvent(PointerHoverEvent());
final PointerExitEvent exitEvent = PointerExitEvent.fromMouseEvent(PointerHoverEvent());参考资料
API 文档
相关问题
相关 PR
showDialog 使用 builder
#由修复工具支持:是
showDialog 的 child 参数在 v0.2.3 中已被弃用。应改用 builder 参数。
迁移指南
迁移前的代码
showDialog(child: myWidget);迁移后的代码
showDialog(builder: (context) => myWidget);参考资料
API 文档
相关问题
相关 PR
Scaffold.resizeToAvoidBottomPadding
#由修复工具支持:是
Scaffold 的 resizeToAvoidBottomPadding 参数在 v1.1.9 中已被弃用。应改用 resizeToAvoidBottomInset 参数。
迁移指南
迁移前的代码
Scaffold(resizeToAvoidBottomPadding: true);迁移后的代码
Scaffold(resizeToAvoidBottomInset: true);参考资料
API 文档
相关问题
- 嵌套 Scaffold 时显示警告
- 键盘附带的 SafeArea
- 双重堆叠的 material Scaffold 不应 double resizeToAvoidBottomPadding
- Window 和 MediaQueryData 的 viewInsets 和 padding 应定义它们如何交互
- 当在 tabbarview 中使用 textfields 时,底部溢出问题
相关 PR
ButtonTheme.bar
#由修复工具支持:否
ButtonTheme 的 bar 构造函数在 v1.9.1 中已被弃用。对于 ButtonBar,可以使用 ButtonBarTheme;如果使用场景不限于 ButtonBar,则可以使用 ButtonTheme 的其他构造函数。
按钮特定的主题也可以通过 TextButtonTheme、ElevatedButtonTheme 和 OutlinedButtonTheme 类获得,每个类分别对应相应的按钮类 TextButton、ElevatedButton 和 OutlinedButton。
迁移指南
迁移前的代码
ButtonTheme.bar(
minWidth: 10.0,
alignedDropdown: true,
height: 40.0,
);迁移后使用 ButtonTheme 的代码
ButtonTheme(
minWidth: 10.0,
alignedDropdown: true,
height: 40.0,
);迁移后使用 ButtonBarTheme 的代码
ButtonBarTheme(
data: ButtonBarThemeData(
buttonMinWidth: 10.0,
buttonAlignedDropdown: true,
buttonHeight: 40.0,
)
);参考资料
API 文档
ButtonThemeButtonBarThemeButtonBarTextButtonTheme文本按钮ElevatedButtonTheme凸起按钮OutlinedButtonThemeOutlinedButton
相关问题
- ButtonTheme.bar 在应使用 primary color 时使用了 accent color
- ThemeData.accentColor 对文本的对比度不足
- 由于 materialTapTargetSize 的更改,AlertDialog/ButtonBar 的高度增加
相关 PR
InlineSpan, TextSpan, PlaceholderSpan
#由修复工具支持:否
为了能够将 widget 内联嵌入段落中(例如图像),InlineSpan、TextSpan 和 PlaceholderSpan 中的以下方法已被弃用。
迁移指南
| 迁移前的代码 | 迁移后的代码 |
|---|---|
InlineSpan.text | TextSpan.text |
InlineSpan.children | TextSpan.children |
InlineSpan.visitTextSpan | InlineSpan.visitChildren |
InlineSpan.recognizer | TextSpan.recognizer |
InlineSpan.describeSemantics | InlineSpan.computeSemanticsInformation |
PlaceholderSpan.visitTextSpan | PlaceHolderSpan.visitChildren |
TextSpan.visitTextSpan | TextSpan.visitChildren |
参考资料
API 文档
相关问题
相关 PR
RenderView.scheduleInitialFrame
#由修复工具支持:否
RenderView.scheduleInitialFrame 方法已被弃用并移除,以防止启动画面过早关闭,导致出现黑屏。当调用 WidgetsFlutterBinding.ensureInitialized 时会出现这种情况。请改用 RenderView.prepareInitialFrame,然后是 RenderView.owner.requestVisualUpdate 来替换对该方法的调用。
迁移指南
迁移前的代码
scheduleInitialFrame();迁移后的代码
prepareInitialFrame();
owner.requestVisualUpdate();参考资料
API 文档
相关问题
相关 PR
Layer.findAll
#由修复工具支持:否
Layer.findAll 方法随着 Layer.findAnnotations 的引入而被弃用,目的是统一 find 和 findAll 的实现。要迁移受影响的代码,请改用 findAllAnnotations。此方法返回一个 AnnotationResult,其中包含 findAll 的前返回值,位于 AnnotationResult.annotations 中。
迁移指南
迁移前的代码
findAll(offset);迁移后的代码
findAllAnnotations(offset).annotations;参考资料
API 文档
相关问题
相关 PR
BinaryMessages
#由修复工具支持:否
BinaryMessages 类、其相关的静态方法和 defaultBinaryMessenger getter 已被弃用并移除。defaultBinaryMessenger 实例已移至 ServicesBinding。这使得在测试环境中注册不同的默认 BinaryMessenger 成为可能,方法是创建一个用于测试的 ServicesBinding 子类。这样做可以让你跟踪待处理的平台消息数量以进行同步。
迁移指南
| 迁移前的代码 | 迁移后的代码 |
|---|---|
defaultBinaryMessenger | ServicesBinding.instance.defaultBinaryMessenger |
BinaryMessages | BinaryMessenger |
BinaryMessages.handlePlatformMessage | ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage |
BinaryMessages.send | ServicesBinding.instance.defaultBinaryMessenger.send |
BinaryMessages.setMessageHandler | ServicesBinding.instance.defaultBinaryMessenger.setMessageHandler |
BinaryMessages.setMockMessageHandler | ServicesBinding.instance.defaultBinaryMessenger.setMockMessageHandler |
参考资料
API 文档
相关问题
相关 PR
BuildContext 的通用方法
#由修复工具支持:是
BuildContext 中的几个方法曾使用 Type 来搜索祖先。其中大多数方法在调用处暗示了一个类型转换,因为它们的返回类型是一个父类型。此外,即使类型实际上受约束,在分析时也不会检查提供的类型。将这些方法改为泛型可以提高类型安全性并减少代码量。
这些方法更改影响了 BuildContext、Element 和 StatefulElement 类。TypeMatcher 类也被移除了。
迁移指南
迁移前的代码
ComplexLayoutState state = context.ancestorStateOfType(const TypeMatcher<ComplexLayoutState>()) as ComplexLayoutState;迁移后的代码
ComplexLayoutState state = context.ancestorStateOfType<ComplexLayoutState>();BuildContext
| 迁移前的代码 | 迁移后的代码 |
|---|---|
inheritFromElement | dependOnInheritedElement |
inheritFromWidgetOfExactType | dependOnInheritedWidgetOfExactType |
ancestorInheritedElementForWidgetOfExactType | getElementForInheritedWidgetOfExactType |
ancestorWidgetOfExactType | findAncestorWidgetOfExactType |
ancestorStateOfType | findAncestorStateOfType |
rootAncestorStateOfType | findRootAncestorStateOfType |
ancestorRenderObjectOfType | findAncestorRenderObjectOfType |
Element
| 迁移前的代码 | 迁移后的代码 |
|---|---|
inheritFromElement | dependOnInheritedElement |
inheritFromWidgetOfExactType | dependOnInheritedWidgetOfExactType |
ancestorInheritedElementForWidgetOfExactType | getElementForInheritedWidgetOfExactType |
ancestorWidgetOfExactType | findAncestorWidgetOfExactType |
ancestorStateOfType | findAncestorStateOfType |
rootAncestorStateOfType | findRootAncestorStateOfType |
ancestorRenderObjectOfType | findAncestorRenderObjectOfType |
StatefulElement
| 迁移前的代码 | 迁移后的代码 |
|---|---|
inheritFromElement | dependOnInheritedElement |
参考资料
API 文档
相关 PR
WidgetsBinding.deferFirstFrameReport 和 WidgetsBinding.allowFirstFrameReport
#由修复工具支持:是
WidgetsBinding 的 deferFirstFrameReport 和 allowFirstFrameReport 方法已被弃用并移除,目的是提供延迟渲染第一帧的选项。这对于需要异步获取初始化信息的 widget 很有用,并且在等待该信息时,不应渲染任何帧,因为这会过早关闭启动画面。应分别使用 deferFirstFrame 和 allowFirstFrame 方法来代替。
迁移指南
迁移前的代码
final WidgetsBinding binding = WidgetsBinding.instance;
binding.deferFirstFrameReport();
binding.allowFirstFrameReport();迁移后的代码
final WidgetsBinding binding = WidgetsBinding.instance;
binding.deferFirstFrame();
binding.allowFirstFrame();参考资料
API 文档
相关 PR
WaitUntilNoTransientCallbacks、WaitUntilNoPendingFrame 和 WaitUntilFirstFrameRasterized
#由修复工具支持:否
flutter_driver 包中的 WaitUntilNoTransientCallbacks、WaitUntilNoPendingFrame 和 WaitUntilFirstFrameRasterized 方法已被弃用并移除,目的是提供一个更具组合性的 waitForCondition API,可用于组合客户端想要等待的条件。
迁移指南
| 迁移前的代码 | 迁移后的代码 |
|---|---|
WaitUntilNoTransientCallbacks | WaitForCondition(NoTransientCallbacks()) |
WaitUntilNoPendingFrame | WaitForCondition(NoPendingFrame()) |
WaitUntilFirstFrameRasterized | WaitForCondition(FirstFrameRasterized)) |
参考资料
API 文档
相关问题
相关 PR
时间线
#稳定版本:2.0.0