getBarcodeStreamReceiver static method

Stream? getBarcodeStreamReceiver(
  1. String lineColor,
  2. String cancelButtonText,
  3. bool isShowFlashIcon,
  4. ScanMode scanMode,
  5. int? delayMillis,
  6. String cameraFace,
)

Returns a continuous stream of barcode scans until the user cancels the operation.

Shows a scan line with lineColor over a scan window. A flash icon is displayed if isShowFlashIcon is true. The text of the cancel button can be customized with the cancelButtonText string. Returns a stream of detected barcode strings.

Implementation

static Stream? getBarcodeStreamReceiver(
    String lineColor,
    String cancelButtonText,
    bool isShowFlashIcon,
    ScanMode scanMode,
    int? delayMillis,
    String cameraFace) {
  if (cancelButtonText.isEmpty) {
    cancelButtonText = 'Cancel';
  }

  // Pass params to the plugin
  Map params = <String, dynamic>{
    'lineColor': lineColor,
    'cancelButtonText': cancelButtonText,
    'isShowFlashIcon': isShowFlashIcon,
    'isContinuousScan': true,
    'scanMode': scanMode.index,
    'delayMillis': delayMillis ?? 0,
    'cameraFacingText': cameraFace
  };

  // Invoke method to open camera, and then create an event channel which will
  // return a stream
  _channel.invokeMethod('scanBarcode', params);
  _onBarcodeReceiver ??= _eventChannel.receiveBroadcastStream();
  return _onBarcodeReceiver;
}