getBestCloseRangeScanningLens method

Future<CameraLensType?> getBestCloseRangeScanningLens({
  1. CameraFacing facing = CameraFacing.back,
})

Determine the lens type best suited for close-range scanning.

Returns the CameraLensType whose camera can focus closest to the phone, making it best suited for scanning barcodes held at close range.

Returns null if the device has no camera for the given facing direction.

This does not switch the camera. Combine it with getSupportedLenses and switchCamera to only switch to the returned lens if it is actually available on the device:

final bestLens = await controller.getBestCloseRangeScanningLens();
final supported = await controller.getSupportedLenses(
  facing: CameraFacing.back,
);

if (bestLens != null && supported.contains(bestLens)) {
  await controller.switchCamera(
    SelectCamera(facingDirection: CameraFacing.back, lensType: bestLens),
  );
}

Throws a MobileScannerException if the controller has been disposed.

Implementation

Future<CameraLensType?> getBestCloseRangeScanningLens({
  CameraFacing facing = CameraFacing.back,
}) async {
  if (_isDisposed) {
    throw MobileScannerException(
      errorCode: MobileScannerErrorCode.controllerDisposed,
      errorDetails: MobileScannerErrorDetails(
        message: MobileScannerErrorCode.controllerDisposed.message,
      ),
    );
  }

  return MobileScannerPlatform.instance.getBestCloseRangeScanningLens(
    facing: facing,
  );
}