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