首页 > 解决方案 > 使用`flutter drive`时如何捕获异常?

问题描述

flutter drive即使堆栈中存在运行时异常,使用我的测试仍然可以通过。

例如,将此代码添加到 build() 中,不会被检测到:

int? i;
i!.round();

有谁知道我怎么能在这个错误上失败?

标签: flutterflutterdriver

解决方案


try{}
catch(e){print('error: $e')}

如果您知道异常,请以这种方式添加:-

try
on
catch

推荐阅读