setHints method

void setHints(
  1. Map<DecodeHintType, Object>? hints
)

This method adds state to the MultiFormatReader. By setting the hints once, subsequent calls to decodeWithState(image) can reuse the same set of readers without reallocating memory. This is important for performance in continuous scan clients.

@param hints The set of hints to use for subsequent calls to decode(image)

Implementation

void setHints(Map<DecodeHintType, Object>? hints) {
  _hints = hints;

  final tryHarder = hints?.containsKey(DecodeHintType.TRY_HARDER) ?? false;
  // @SuppressWarnings("unchecked")
  final formats =
      hints?[DecodeHintType.POSSIBLE_FORMATS] as List<BarcodeFormat>?;
  final readers = <Reader>[];
  if (formats != null) {
    final addOneDReader = formats.contains(BarcodeFormat.UPC_A) ||
        formats.contains(BarcodeFormat.UPC_E) ||
        formats.contains(BarcodeFormat.EAN_13) ||
        formats.contains(BarcodeFormat.EAN_8) ||
        formats.contains(BarcodeFormat.CODABAR) ||
        formats.contains(BarcodeFormat.CODE_39) ||
        formats.contains(BarcodeFormat.CODE_93) ||
        formats.contains(BarcodeFormat.CODE_128) ||
        formats.contains(BarcodeFormat.ITF) ||
        formats.contains(BarcodeFormat.RSS_14) ||
        formats.contains(BarcodeFormat.RSS_EXPANDED);
    // Put 1D readers upfront in "normal" mode
    if (addOneDReader && !tryHarder) {
      readers.add(MultiFormatOneDReader(hints));
    }
    if (formats.contains(BarcodeFormat.QR_CODE)) {
      readers.add(QRCodeReader());
    }
    if (formats.contains(BarcodeFormat.DATA_MATRIX)) {
      readers.add(DataMatrixReader());
    }
    if (formats.contains(BarcodeFormat.AZTEC)) {
      readers.add(AztecReader());
    }
    if (formats.contains(BarcodeFormat.PDF_417)) {
      readers.add(PDF417Reader());
    }
    if (formats.contains(BarcodeFormat.MAXICODE)) {
      readers.add(MaxiCodeReader());
    }
    // At end in "try harder" mode
    if (addOneDReader && tryHarder) {
      readers.add(MultiFormatOneDReader(hints));
    }
  }
  if (readers.isEmpty) {
    if (!tryHarder) {
      readers.add(MultiFormatOneDReader(hints));
    }

    readers.add(QRCodeReader());
    readers.add(DataMatrixReader());
    readers.add(AztecReader());
    readers.add(PDF417Reader());
    readers.add(MaxiCodeReader());

    if (tryHarder) {
      readers.add(MultiFormatOneDReader(hints));
    }
  }
  _readers = readers; //.toList();
}