takePicture method
Captures a photo using the native OS camera interface.
Requests camera permission if necessary. Returns null if the user cancels or permission is denied.
Example:
final photo = await camera.takePicture(
preferredCamera: CameraDevice.front,
maxWidth: 1024,
imageQuality: 90,
);
Implementation
Future<BloomCapturedPhoto?> takePicture({
CameraDevice preferredCamera = CameraDevice.rear,
double? maxWidth,
double? maxHeight,
int? imageQuality,
}) async {
final status = await BloomPermissions.request(BloomPermission.camera);
if (!status.isGranted) {
logger.warn('BloomCamera: Camera permission denied. Cannot take picture.');
return null;
}
try {
logger.info('BloomCamera: Launching native camera capture...');
final XFile? file = await _picker.pickImage(
source: ImageSource.camera,
preferredCameraDevice: preferredCamera,
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: imageQuality,
);
if (file == null) {
logger.info('BloomCamera: Capture cancelled by user.');
return null;
}
final bytes = await file.readAsBytes();
logger.info('BloomCamera: Captured photo saved to: ${file.path} (${bytes.length} bytes)');
return BloomCapturedPhoto(
path: file.path,
bytes: bytes,
mimeType: file.mimeType ?? 'image/jpeg',
);
} catch (e, st) {
logger.error('BloomCamera: Camera capture failed: $e', e, st);
return null;
}
}