flutter - 颤振:处理 File.path 空/空
问题描述
我有File
名字 _pickedImage。我面临处理 File.path null 的问题,我已经path
用这段代码处理了 null :
if (pickedImage.path == null)
或者
if (pickedImage.path.isEmpty)
每次我按下按钮时,我都无法处理 File.pathnull
并且我收到此错误。
═══════ Exception caught by gesture ═══════════════════════════════════════════
The following NoSuchMethodError was thrown while handling a gesture:
The getter 'path' was called on null.
Receiver: null
Tried calling: path
Handler: "onTap"
Recognizer: TapGestureRecognizer#c9d89
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(246.8, 613.3)
finalLocalPosition: Offset(246.8, 23.3)
button: 1
sent tap down
我做错了吗?
解决方案
═══════ Exception caught by gesture ═══════════════════════════════════════════
The following NoSuchMethodError was thrown while handling a gesture:
The getter 'path' was called on null.
Receiver: null
Tried calling: path
该错误仅仅是因为您试图从null File
.
在调用下一个代码之前,您需要检查文件是否为空:
if (pickedImage == null) {
// File is null, probably not found or incorrect path.
return;
}
// Do something with the file
if (pickedImage.path == null) {
}
推荐阅读
- mysql - 无法连接到 jenkins 管道上的 myslq docker 容器
- javascript - 在我的 Angular 表单中获取'TypeError:无法读取未定义的属性'错误'
- javascript - 无法将带有 javascript 的帖子发送到另一个页面
- python - 将多处理池(生产者)与进程(消费者)混合
- entity-framework - Entity Framework Core:如何使用嵌套字段更新记录?
- javascript - ES6 链式访问 Next 方法的内容
- python - 熊猫忽略丢失的日期以查找百分位数
- c - 如何在 Linux 中读取和更改内存中的值?
- c - C - 找不到内存泄漏
- python - 当另一列与python中的值匹配时,熊猫仅获取一列的平均(浮点)值