ancestorStateOfType已过时,请改用findAncestorStateOfType [英] ancestorStateOfType is deprecated use findAncestorStateOfType instead

查看:1747
本文介绍了ancestorStateOfType已过时,请改用findAncestorStateOfType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自Flutter 1.12发布以来,我的以下代码用于重新启动应用程序:

Since the release of Flutter 1.12 my following code for restarting the app:

final MyAppState state = context.ancestorStateOfType(const TypeMatcher<MyAppState>()):

警告以下内容:


'ancestorStateOfType'已被弃用,不应使用。请改用findAncestorStateOfType。 v1.12.1之后不推荐使用此功能。请尝试使用替换的成员来替换不推荐使用的成员。

'ancestorStateOfType' is deprecated and shouldn't be used. Use findAncestorStateOfType instead. This feature was deprecated after v1.12.1.. Try replacing the use of the deprecated member with the replacement.


'TypeMatcher'已过时,不应使用。 TypeMatcher已被弃用,因为它不再在框架中使用(仅在不建议使用的方法中使用)。 v1.12.1之后不推荐使用此功能。尝试用替换功能替换不推荐使用的成员。

'TypeMatcher' is deprecated and shouldn't be used. TypeMatcher has been deprecated because it is no longer used in framework(only in deprecated methods). This feature was deprecated after v1.12.1.. Try replacing the use of the deprecated member with the replacement.

出于某种原因,我可以似乎没有弄清楚如何重构此代码以使其正常工作。

For some reason I can't seem to figure out how to refactor this code to get it working. Anyone to the rescue?

推荐答案

您所要做的就是将扩展了 State< StatefulWidget> ,因此,由于该类称为 MyAppState ,因此我假设它扩展了 State< MyApp> 因此,

All you have to do is just put the widget that extends State<StatefulWidget> so for your example, since the class is called MyAppState, I'm assuming it extends State<MyApp> so, therefore:

final MyAppState state = context.findAncestorStateOfType<MyAppState>();

这篇关于ancestorStateOfType已过时,请改用findAncestorStateOfType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆