start method

  1. @override
Future<void> start({
  1. required CameraFacing cameraFacing,
  2. List<BarcodeFormat>? formats,
  3. Duration? detectionTimeout,
})
override

Starts streaming video

Implementation

@override
Future<void> start({
  required CameraFacing cameraFacing,
  List<BarcodeFormat>? formats,
  Duration? detectionTimeout,
}) async {
  final JsMap? hints;
  if (formats != null && !formats.contains(BarcodeFormat.all)) {
    hints = JsMap();
    final zxingFormats =
        formats.map((e) => e.zxingBarcodeFormat).where((e) => e > 0).toList();
    // set hint DecodeHintType.POSSIBLE_FORMATS
    // https://github.com/zxing-js/library/blob/1e9ccb3b6b28d75b9eef866dba196d8937eb4449/src/core/DecodeHintType.ts#L28
    hints.set(2, zxingFormats);
  } else {
    hints = null;
  }
  if (detectionTimeout != null) {
    frameInterval = detectionTimeout;
  }
  _reader = JsZXingBrowserMultiFormatReader(
    hints,
    frameInterval.inMilliseconds,
  );
  videoContainer.children = [video];

  final stream = await initMediaStream(cameraFacing);

  prepareVideoElement(video);
  if (stream != null) {
    await attachStreamToVideo(stream, video);
  }
}