Created
December 3, 2019 12:01
-
-
Save guilhermecarvalhocarneiro/fc8d678893713b39a1e2ba06891e872c 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
// Versões das libs | |
// image_picker: ^0.6.2+1 | |
// image_cropper: ^1.1.1 | |
// Função para tirar uma foto ou escolher da galeria | |
choiceProfilePicture({gallery = false}) async { | |
File fileImage; | |
try { | |
fileImage = await ImagePicker.pickImage( | |
source: gallery ? ImageSource.gallery : ImageSource.camera); | |
fileImage = await _cropImage(fileImage); | |
Directory appDocDir = await getExternalStorageDirectory(); | |
final String appDocPathDir = "${appDocDir.path}/Pictures/"; | |
// Criando o diretório | |
await Directory(appDocPathDir).create(recursive: true); | |
newPicture = await fileImage | |
.copy("$appDocPathDir/${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