Created
December 3, 2019 10:49
-
-
Save guilhermecarvalhocarneiro/d91f991a8fe9cf2277b68660bbc5f040 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
// Função para tirar uma foto ou escolher da galeria | |
choiceProfilePicture({gallery = false}) async { | |
UsuarioProvider _usuarioProvider = | |
Provider.of<UsuarioProvider>(context, listen: false); | |
File fileImage; | |
try { | |
final Directory savePath = await getExternalStorageDirectory(); | |
final String savePathStr = "${savePath.path}/Pictures/Vestter"; | |
fileImage = await ImagePicker.pickImage( | |
source: gallery ? ImageSource.gallery : ImageSource.camera); | |
fileImage = await _cropImage(fileImage); | |
// Criando o diretório | |
await Directory(savePathStr).create(recursive: true); | |
// Salvando na galeria | |
newPicture = await fileImage | |
.copy("$savePathStr/${fileImage.path.split("/").last}"); | |
} catch (e) { | |
DebugPrint.error("Erro ao tentar recuperar a imagem $e"); | |
showMessage("Erro ao acessar a imagem.", error: true); | |
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