detectCodes method

Future<List<UArCodeResult>> detectCodes({
  1. UCodeScanOptions options = const UCodeScanOptions(multiple: true),
})

Reads QR codes and barcodes in view — Apple Vision on iOS, the bundled Dart decoder on the camera frame elsewhere.

Implementation

Future<List<UArCodeResult>> detectCodes({UCodeScanOptions options = const UCodeScanOptions(multiple: true)}) async {
  if (value.capabilities.barcodeDetection) {
    try {
      final List<Object?>? raw = await _invoke<List<Object?>>("detectBarcodes");
      if (raw != null) return _maps(raw).map(UArCodeResult.fromMap).toList(growable: false);
    } on UArException catch (_) {}
  }
  final UArCameraImage? image = await cameraImage();
  if (image == null || image.bytes.isEmpty) return const <UArCodeResult>[];
  final List<UCode> codes = await UCodeScanWorker.decode(image.bytes, image.width, image.height, image.stride, options);
  return codes.map((UCode code) => UArCodeResult(text: code.text, format: code.format.name, corners: code.corners.map(image.toView).toList(growable: false))).toList(growable: false);
}