Created
December 2, 2019 21:02
-
-
Save guilhermecarvalhocarneiro/2cecdbcd9c930c5b645d80889fbcb51b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
choiceProfilePicture({gallery = false}) async { | |
File fileImage; | |
try { | |
final Directory savePath = await getApplicationDocumentsDirectory(); | |
final String savePathStr = savePath.path; | |
fileImage = await ImagePicker.pickImage( | |
source: gallery ? ImageSource.gallery : ImageSource.camera); | |
fileImage = await _cropImage(fileImage); | |
// Salvando o arquivo | |
newPicture = await fileImage.copy("$savePathStr/${fileImage.path.split("/").last}"); | |
} catch (e) { | |
DebugPrint.error("Erro ao tentar recuperar a imagem $e"); | |
return null; | |
} | |
} | |
Future<File> _cropImage(File imageFile) async { | |
File croppedFile = await ImageCropper.cropImage( | |
sourcePath: imageFile.path, | |
ratioX: 1, | |
ratioY: 1, | |
maxWidth: 300, | |
maxHeight: 300, | |
); | |
return croppedFile; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment