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
构造的指针事件
#受修复工具支持:是
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 文档
相关问题
- 嵌套 Scaffolds 时显示警告
- 带键盘的 SafeArea
- 双层堆叠的 Material Scaffold 不应双重使用 resizeToAvoidBottomPadding
- Window 和 MediaQueryData 上的 viewInsets 和 padding 应定义其交互方式
- 在 tabbarview 中使用文本字段时,底部溢出问题
相关 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 文档
ButtonTheme
ButtonBarTheme
ButtonBar
TextButtonTheme
文本按钮
ElevatedButtonTheme
凸起按钮
OutlinedButtonTheme
OutlinedButton
相关问题
- ButtonTheme.bar 在应该使用主色时使用了强调色
- ThemeData.accentColor 对文本的对比度不足
- 由于 materialTapTargetSize 更改影响 AlertDialog/ButtonBar 高度而导致的高度增加
相关 PR
InlineSpan
、TextSpan
、PlaceholderSpan
#受修复工具支持:否
为了实现在段落中内嵌小部件(如图片),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
#受修复工具支持:否
为了统一 find
和 findAll
的实现,Layer.findAll
方法随着 Layer.findAnnotations
的引入而被弃用。要迁移受影响的代码,请改用 findAllAnnotations
。此方法返回一个 AnnotationResult
,其中包含 findAll
之前的返回值,存储在 AnnotationResult.annotations
中。
迁移指南
迁移前的代码
findAll(offset);
迁移后的代码
findAllAnnotations(offset).annotations;
参考资料
API 文档
相关问题
相关 PR
BinaryMessages
#受修复工具支持:否
BinaryMessages
类、其关联的静态方法和 defaultBinaryMessenger
getter 已弃用并移除。defaultBinaryMessenger
实例已移至 ServicesBinding
。通过为测试创建 ServicesBinding
子类,可以在测试环境下注册不同的默认 BinaryMessenger
。这样做可以跟踪待处理的平台消息数量,以实现同步目的。
迁移指南
迁移前的代码 | 迁移后的代码 |
---|---|
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
方法已弃用并移除。这对于需要异步获取初始化信息的小部件很有用,当它们等待这些信息时,不应渲染任何帧,因为这会过早地移除启动画面。应分别改用 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
#受修复工具支持:否
为了提供更具组合性的 waitForCondition
API(可用于组合客户端希望等待的条件),flutter_driver
包中的 WaitUntilNoTransientCallbacks
、WaitUntilNoPendingFrame
和 WaitUntilFirstFrameRasterized
方法已弃用并移除。
迁移指南
迁移前的代码 | 迁移后的代码 |
---|---|
WaitUntilNoTransientCallbacks | WaitForCondition(NoTransientCallbacks()) |
WaitUntilNoPendingFrame | WaitForCondition(NoPendingFrame()) |
WaitUntilFirstFrameRasterized | WaitForCondition(FirstFrameRasterized)) |
参考资料
API 文档
相关问题
相关 PR
时间线
#稳定版本:2.0.0