Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermecarvalhocarneiro/d91f991a8fe9cf2277b68660bbc5f040 to your computer and use it in GitHub Desktop.
Save guilhermecarvalhocarneiro/d91f991a8fe9cf2277b68660bbc5f040 to your computer and use it in GitHub Desktop.
// 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