Flutter 颤振:查找停用的小部件';的祖先使用PushName和RemoveUntil是不安全的
这发生在第二行,如果我把它注释掉,一切都很好:Flutter 颤振:查找停用的小部件';的祖先使用PushName和RemoveUntil是不安全的,flutter,Flutter,这发生在第二行,如果我把它注释掉,一切都很好: login(BuildContext context, bool fromExample, String method) async { final loading = new Loading(); await loading.load(context, 'loads_logging_in'.tr); switch (method) { case "Facebook": await authServ
login(BuildContext context, bool fromExample, String method) async {
final loading = new Loading();
await loading.load(context, 'loads_logging_in'.tr);
switch (method) {
case "Facebook":
await authService.facebookSignIn(context);
break;
case "Google":
await authService.googleSignIn(context);
break;
case "Apple":
await authService.appleSignIn(context);
break;
}
loading.cancel();
if (authService.getUser() == null) {
return false;
}
Navigator.pushNamedAndRemoveUntil(context, '/', (_) => false); // THIS LINE THROWS THE ERROR
}
即使我只有那一行,我也会得到完全相同的错误:
================================================================================================================在完成小部件树时引发了以下断言:查找
停用的小部件的祖先不安全
此时,小部件的元素树的状态不再是
马厩
要在小部件的dispose()方法中安全地引用其祖先,请保存
通过调用
在小部件的
didChangeDependencies()方法。
引发异常时,这是堆栈:
#0元素。\u debugcheckstatesactiveforancestorlookup。(包:flatter/src/widgets/framework.dart:3864:9)
#1元素。_debugcheckstatesactiveforancestorlookup(包:flatter/src/widgets/framework.dart:3878:6)
#2 Element.getElementForInheritedWidgetOfExactType(包:flatter/src/widgets/framework.dart:3905:12)
#3 Provider.\u inheritedElementOf(包:Provider/src/Provider.dart:327:34)
#4 Provider.of(包:Provider/src/Provider.dart:284:30)
将该行替换为
Navigator.of(context.pushNamed('/')代码>修复了该问题该错误与我重定向到的默认页面上的某个提供商有关:
@override
void dispose() {
Provider.of<AdState>(context, listen: false).getInterstitial()?.dispose();
super.dispose();
}
@覆盖
无效处置(){
Provider.of(context,listen:false).getinterstitual()?.dispose();
super.dispose();
}