这是我的函数,当我返回文件对象
时,我得到错误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安全。您需要在声明为空的变量上添加空检查(!)?.