start static method

Future<void> start({
  1. HVBarcodeConfig? hvBarcodeConfig,
  2. required void onComplete(
    1. Map?,
    2. HVError?
    ),
})

Starts the barcode scanning and capture process.

Use this method to initiate the barcode scanning and capture process. Provide the necessary configuration options through the hvBarcodeConfig parameter. The result of the scanning process will be returned through the onComplete callback function.

The hvBarcodeConfig parameter is optional and allows you to customize the barcode scanning configuration. If not provided, a default HVBarcodeConfig instance will be used.

The onComplete callback function takes two parameters: hvResponse and hvError. hvResponse contains the result of the barcode scanning process, while hvError represents any errors that occurred during the process. At least one of these parameters will be non-null.

Example usage:

HVBarcodeConfig barcodeConfig = HVBarcodeConfig();
HVBarcodeCapture.start(
  hvBarcodeConfig: barcodeConfig,
  onComplete: (HVResponse? response, HVError? error) {
    if (response != null) {
      // Barcode scanning succeeded, handle the response
    } else if (error != null) {
      // Barcode scanning failed, handle the error
    }
  },
);

Implementation

static Future<void> start({
  HVBarcodeConfig? hvBarcodeConfig,
  required void Function(Map?, HVError?) onComplete,
}) async {
  try {
    final resMap = await _hvBarcodeScanCaptureChannel.invokeMethod(
      HyperSnapSDKConstants.qrScanCaptureStart,
      {
        HyperSnapSDKConstants.hvQRConfig:
            hvBarcodeConfig?.toMap() ?? HVBarcodeConfig().toMap(),
      },
    );

    final errorObj = resMap["errorObj"] as Map;
    final hvError = errorObj.isEmpty ? null : HVError.fromMap(errorObj);
    final resObj = resMap["resultObj"] as Map;

    onComplete(resObj, hvError);
  } catch (e) {
    log(e.toString());
  }
}