gpt4 book ai didi

flutter - 不推荐使用ancestorStateOfType 使用findAncestorStateOfType 代替

转载 作者:行者123 更新时间:2023-12-03 02:41:31 25 4
gpt4 key购买 nike

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

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

警告如下:

'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' 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.



出于某种原因,我似乎无法弄清楚如何重构此代码以使其正常工作。有人来救吗?

最佳答案

您所要做的就是放置扩展 State<StatefulWidget> 的小部件所以对于你的例子,因为这个类被称为 MyAppState ,我假设它扩展 State<MyApp>所以,因此:

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

关于flutter - 不推荐使用ancestorStateOfType 使用findAncestorStateOfType 代替,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59448102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com