flutter - 'Future 类型的值' 无法从该方法返回,因为它的返回类型为 'Future
问题描述
Future<bool> foo(BuildContext context) {
return Navigator.pushNamed<bool>(context, '/bar'); // Error
}
错误:
无法从函数“foo”返回“Future<bool?>”类型的值,因为它的返回类型为“Future”
解决方案
Navigator.push
无法返回不可为空的类型,因为在您的/bar
路由中,您可能会执行以下操作,而无需在结果参数中传递任何值。
Navigator.pop(context);
您应该将签名从更改Future<bool>
为Future<bool?>
:
Future<bool?> foo(BuildContext context) {
return Navigator.pushNamed<bool>(context, '/bar');
}
推荐阅读
- javascript - 在自动完成列表中使用向上和向下键滚动
- xml - XSLT:在 for-each 中使用 if 有异常
- python - 在 Windows10 32bit Python3 中安装 PyQt5
- excel - Power BI:折线图上的最小值/最大值,值选项卡上没有第二个实例
- node.js - Sinon Fake Timer 在测试中多次调用仅触发一次
- xml - xslt 替换一个节点
- javascript - 开玩笑的异步测试忽略了expect()函数
- reporting-services - SSRS 在导出为 CSV 时添加额外字符
- python - Python删除停用词(熊猫数据框):输出与输入相同
- c# - 替换为