Skip to content

Instantly share code, notes, and snippets.

@Ayush783
Created November 7, 2020 22:07
Show Gist options
  • Save Ayush783/b2622136afef8c305a5b42bc33901664 to your computer and use it in GitHub Desktop.
Save Ayush783/b2622136afef8c305a5b42bc33901664 to your computer and use it in GitHub Desktop.
class Capture {
File image;
final picker = ImagePicker(); //instantiate the image picker object
Future<CapturedImage> getImage() async {
final pickedFile =
await picker.getImage(source: ImageSource.camera, imageQuality: 50); //capture the image
if (pickedFile != null) {
image = File(pickedFile.path);
return CapturedImage.fromFile(image); //if image is not null return our image model with the image
} else {
return CapturedImage.fromError('Please try again'); // else return with error
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment