startBarcodeScannerV2 static method

Implementation

static Future<ResultWrapper<rtu_ui.BarcodeScannerResult>>
    startBarcodeScannerV2(MethodChannel channel,
        rtu_ui.BarcodeScannerConfiguration config) async {
  try {
    var updatedParameters = config.toJson();

    if (isUsecaseSupportBarcodeFormatterV2(config)) {
      var formatter = getBarcodeFormatterV2(config.useCase);
      if (formatter != null) {
        _initBarcodeFormatterHandlerV2(
            _barcodeFormatterCallbackChannelV2, formatter);

        _barcodeFormatterCallbackChannelV2.setMethodCallHandler(_handlerV2);
        updatedParameters['shouldUseBarcodeFormatter'] = true;
      }
    }

    var barcodeScanningResult = await channel.invokeMethod(
        'startBarcodeScannerV2', updatedParameters);

    _handlerV2 = null;

    if (wasCanceled(barcodeScanningResult)) {
      return ResultWrapper.canceled();
    }
    var decoded = jsonDecode(barcodeScanningResult);
    return ResultWrapper.success(
        rtu_ui.BarcodeScannerResult.fromJson(decoded));
  } catch (e) {
    Logger.root.severe(e);
    return ResultWrapper.error(e.toString());
  }
}