参数类型'String?'不能分配给参数类型"字符串"。返回文件对象时收到此错误



这是我的函数,当我返回文件对象

时,我得到错误
static Future<File> pickFile() async {
final result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['pdf'],
);
if (result == null) {
throw Exception('No files picked or file picker was canceled');
}
return File(result.paths.first);

}

这是null安全。您需要在声明为空的变量上添加空检查(!)?.

相关内容