detect method

  1. @override
Future<Payload?> detect(
  1. DetectableImage detectable,
  2. List<BarcodeFormats>? formats,
  3. bool? tryharder,
  4. bool? invert,
)
override

Implementation

@override
Future<Payload?> detect(DetectableImage detectable,
    List<BarcodeFormats>? formats, bool? tryharder, bool? invert) async {
  try {
    // load zxing library
    await zxing.loadLibrary();

    dynamic image = detectable.image;
    if (image == null) return null;

    //set barcode format
    formats ??= [];

   // multi form read
   if (formats.length != 1) return await _multi(image, formats, tryharder, invert);

   // specific barcode format
   switch (formats[0]) {
     case BarcodeFormats.code39:
       return await _code39(image, tryharder, invert);
     case BarcodeFormats.pdf417:
       return await _pdf417(image, tryharder, invert);
     case BarcodeFormats.ondl:
       return await _ondl(image, tryharder, invert);
     case BarcodeFormats.qrcode:
       return await _qrcode(image, tryharder, invert);
     default:
       return null;
   }
  }
  catch (e) {
    Log().info("No barcode found");
    return null;
  }
}