flutter - 是否有任何解决方案可以解决此错误尝试调用:findAncestorStateOfType()?
问题描述
我试图通过使用加载对话框导航到另一个页面。
waiting(BuildContext context) {
return showDialog(
context: context,
builder: (BuildContext context) {
// return object of type Dialog
return WillPopScope(
onWillPop: () async => false,
child: AlertDialog(
key: _keyLoader,
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
child: CircularProgressIndicator(),
),
Container(
child: Text("Loading..."),
)
],
)),
);
},
);
}
上面的代码是我的加载对话框。当调用 onPressed 函数时,我想导航到另一个页面。当调用 onPressed 函数时,调用下面的方法。
void _validateInputs(BuildContext context) {
waiting(context);
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
setState(() {
_autoValidate = false;
});
Navigator.of(_keyLoader.currentContext).pop();
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) {
return CareerDetailsPage();
}));
_formKey.currentState.reset();
} else {
setState(() {
_autoValidate = true;
});
}
}
我想弹出这个加载对话框并导航到另一个页面。但我得到了以下类型的错误。
The following NoSuchMethodError was thrown while handling a gesture:
The method 'findAncestorStateOfType' was called on null.
Receiver: null
Tried calling: findAncestorStateOfType<NavigatorState>()
你能帮我么?
解决方案
推荐阅读
- c# - 如何在c#中通过位图查找图像边框?
- python - 从单词中删除特殊字符
- php - 如何使用twitter流api自动接收基于某个单词的通知
- events - 当用户离开(或被移除)团队时,与 team_join 等效的 slack 事件是什么
- django - 在 DRF 路由中定义名称空间
- android - 真实设备未在 android studio 中显示
- .net - excel vba sum multi sheet得到运行时错误1004:应用程序定义或对象定义错误
- sql - 如果列值低于其他列,则选择条件
- laravel-5.5 - 如何从数据库中获取单个值而不是 laravel 中的数组?
- ios - ContentViews Subview 在 UIScrollView iOS 中没有动态改变高度