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/fc8d678893713b39a1e2ba06891e872c to your computer and use it in GitHub Desktop.
Save guilhermecarvalhocarneiro/fc8d678893713b39a1e2ba06891e872c to your computer and use it in GitHub Desktop.
// 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