自Flutter 1.12发布以来,我的以下代码:
static MyInheritedWidget of(BuildContext context) {
return context.inheritFromWidgetOfExactType(MyInheritedWidget) as MyInheritedWidget;
}
警告如下:
“inheritFromWidgetOfExactType”已弃用,不应使用。请改用dependOnInheritedWidgetOfExactType。此功能在v1.12.1之后已弃用。请尝试使用替换项替换已弃用的成员。
但是当我试图替换它时,它不起作用:
static MyInheritedWidget of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType(MyInheritedWidget) as MyInheritedWidget;
}
有人知道怎么做吗?谢谢!
2条答案
按热度按时间rqdpfwrv1#
API略有变化。
现在,该方法不再使用
Type
作为参数,而是泛型的。之前:
之后:
请注意,造型不再需要了
oxf4rvwz2#
InheritFromWidgetOfExactType方法已弃用,请改用dependOnInheritedWidgetOfExactType方法。
替换示例:
**之前:**带InheritFromWidgetOfExactType
现在使用dependOnInheritedWidgetOfExactType(推荐)
现在不再使用
Type
作为参数,该方法是泛型的。简要介绍
<...>()
而不是(...)