不建议使用InheritedFromWidgetOfExactType,而是使用dependOnOnInheritedWidgetOfExactType


23

自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;
}

有人知道怎么做吗?谢谢!

Answers:


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.