startBatchBarcodeScanner static method

Future<BarcodeScanningResult> startBatchBarcodeScanner(
  1. MethodChannel channel,
  2. BatchBarcodeScannerConfiguration config
)

Starts the Ready-to-Use Batch Barcode Scanner UI as full-screen modal UI dialog. The Barcode Scanner is able to recognize 1D- and 2D-barcodes (QR codes, etc).

Implementation

static Future<BarcodeScanningResult> startBatchBarcodeScanner(
    MethodChannel channel, BatchBarcodeScannerConfiguration config) async {
  try {
    if (config.barcodeFormats == null) {
      config.barcodeFormats = PredefinedBarcodes.allBarcodeTypes();
    } else if (config.barcodeFormats!.isEmpty) {
      config.barcodeFormats = PredefinedBarcodes.allBarcodeTypes();
    }
    var updatedParameters = config.toJson();

    if (config.barcodeFormatter != null) {
      _initBatchFormatterHandler(
          _batchBarcodeFormatterCallbackChannel, config.barcodeFormatter!);
      _batchBarcodeFormatterCallbackChannel.setMethodCallHandler(_handler);
      updatedParameters['shouldUseBarcodeFormatter'] = true;
    } else {
      _handler = null;
    }

    const defaultJsonName = "BatchBarcodeScreen";
    var configuration = await applyParametersOnDefaultJson(
        defaultJsonName, updatedParameters);
    var barcodeScanningResult =
        await channel.invokeMethod('startBatchBarcodeScanner', configuration);
    _handler = null;
    if (wasCanceled(barcodeScanningResult)) {
      return BarcodeScanningResult.canceled();
    }
    return BarcodeScanningResult.fromJson(jsonDecode(barcodeScanningResult));
  } catch (e) {
    Logger.root.severe(e);
    return BarcodeScanningResult.error(e.toString());
  }
}