dart 我的代码中出现了这个错误,属性'path'不能无条件访问,因为接收器可以是'null' [已关闭]

nwnhqdif  于 2023-06-19  发布在  其他
关注(0)|答案(1)|浏览(133)

**关闭。**此题需要debugging details。目前不接受答复。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答这个问题。
昨天关门了。
Improve this question
enter image description here问题在于compress()方法; return File(compressedvideo.path).有什么解决的办法吗?
我试过这个,但它对我不起作用。尝试设置访问条件(使用'?.')或向目标('!').

nhaq1z21

nhaq1z211#

实际上,你是在尝试使用一个可选对象,而不打开它。
File()构造函数接受非可选值,因此您需要首先解包该值。
如果path变量为null,则“!”将被强制解包并可能崩溃。你可以把条件检查如果path != null然后使用.path!.

if (var.path != null) { 
    var file = File(var.path!) 
  }

相关问题