getter'printable'在null上被调用

问题描述

我正在使用exif插件来识别图像的方向。但这显示错误之后的错误

I/Flutter ( 7355): Exception in image -- NoSuchMethodError: The getter 'printable' was called on null.

这是我的代码

//设置图像方向的方法 fixExifRotation(String imagePath)异步{ 最后的originalFile = File(imagePath);

List<int> imageBytes = await originalFile.readAsBytes();

final originalImage = img.decodeImage(imageBytes);

final height = originalImage.height;
final width = originalImage.width;

// We'll use the exif package to read exif data
// This is map of several exif properties
// Let's check 'Image Orientation'
final exifData = await readExifFromBytes(imageBytes);

for (String key in exifData.keys) {
  print("$key (${exifData[key].tagType}): ${exifData[key]}");
}

img.Image fixedImage;
if (exifData['Image Orientation'].printable.contains('Rotated 180')) {
    fixedImage = img.copyRotate(originalImage,180);
}else if (exifData['Image Orientation'].printable.contains('Horizontal (normal)')) {
  return originalFile;
} else{
  return originalFile;
}
final fixedFile = await originalFile.writeAsBytes(img.encodeJpg(fixedImage));
return fixedFile;   }

问题在

final exifData = await readExifFromBytes(imageBytes);

解决方法

您没有提及图片的来源

在我的情况下,我使用的是image_picker,问题是使用仿真器拍照。使用真实的设备可以达到目的