startScanning method

Future<void> startScanning(
  1. void resultsCallback(
    1. BarkoderResult
    )
)

Initiates the barcode scanning process, allowing the application to detect and decode barcodes from the device's camera feed.

resultsCallback: A function to handle the scanning results.

Example usage:

_barkoder.startScanning((result) {
  _updateState(result, false);
});
print('Scanning started');

Implementation

Future<void> startScanning(void Function(BarkoderResult) resultsCallback) {
  if (_isBarkoderViewNotMounted) {
    return Future.error(PlatformException(
        code: BarkoderErrors.barkoderViewNotMounted,
        message: BarkoderErrors.barkodeViewNotMountedDesc));
  }

  _clearScanningResultsStreamSubscription();
  _scanningResultsStreamSubscription = _scanningResultsStream.listen(
      (result) =>
          resultsCallback.call(BarkoderResult.fromJsonString(result)));

  return _methodChannel.invokeMethod('startScanning');
}