Image is 90 degree left rotated after encoding to Base64 Flutter

35 Views Asked by At

I am using the chooseImage function to pick an image and sending the avatar value to the server. The problem is sometimes some image is changed its original orientation. Most of time it rotate to left 90 degree. Is there any problem in my code? How can I solve this ?

I am using this package to pick image:

image_picker: ^1.0.4

final imageFile = useState<File?>(null);
final avatar = useState('');

Future<void> chooseImage(type) async {
  XFile? image;
  if (type == "camera") {
    image = await ImagePicker().pickImage(source: ImageSource.camera);
  } else {
    image = await ImagePicker().pickImage(source: ImageSource.gallery);
  }
  if (image != null) {
    imageFile.value = File(image.path);
    final bytes = imageFile.value!.readAsBytesSync();
    avatar.value = 
      Uri.dataFromBytes(bytes, mimeType: "appication/png").toString()
    ;
  }
}
0

There are 0 best solutions below