Skip to content

Reader options ​

ReaderOptions sets how hard the engine looks for codes. The defaults suit photos and files: every search strategy is on. ReaderOptions.camera(), the default of the scanner, leaves out light-on-dark codes, so each camera frame takes less work.

dart
const photos = BarcodeReader(); // ReaderOptions()
const frames = BarcodeReader(options: ReaderOptions.camera());
const pure = BarcodeReader(
  formats: {BarcodeFormat.qrCode},
  options: ReaderOptions(isPure: true),
);
OptionDefaultWhat it does
tryHardertrueSpend more time to find codes in difficult images
tryRotatetrueAlso look for codes turned by 90°, 180° and 270°
tryInverttrue, false in camera()Also look for light-on-dark codes
tryDownscaletrueAlso search a smaller copy of large images; finds big, blurry codes
isPurefalseThe image is exactly one clean, unrotated, tightly cropped code
returnErrorsfalseAlso return codes that were found but could not be decoded, with their error
validateOptionalChecksumfalseCheck the optional checksums of Code 39 and ITF, and drop codes that fail
binarizerBinarizer.localAverageHow the image turns black and white, below
minLineCount2For linear codes, how many scan lines must agree; more means fewer false reads on noisy images
eanAddOnEanAddOn.ignoreThe EAN-2/EAN-5 add-on next to some EAN and UPC codes, below
characterSetnoneThe character set of codes that declare none, below

copyWith changes some fields of a set:

dart
final ReaderOptions dark = const ReaderOptions.camera().copyWith(tryInvert: true);

Binarizer ​

BinarizerFor
localAverageA threshold from the neighbourhood of each pixel; best for uneven light. The default.
globalHistogramOne threshold from the histogram; fast, for even light
fixedThresholdA fixed threshold at mid grey
boolCastAny non-zero pixel is light; for images that are black and white already

EAN and UPC add-ons ​

Books carry the price and magazines the issue in a small EAN-5 or EAN-2 code next to the main one.

EanAddOnWhat happens
ignoreRead the main code only, whether or not there is an add-on. The default.
readAppend the add-on to the text when there is one
requireReport EAN and UPC codes only together with an add-on

Character sets ​

A code can declare its character set with an ECI. For one that does not, the engine guesses the set from the bytes, which can go wrong for short texts: old labels in Windows-1251 or Shift_JIS then read as garbled text. Name the set the codes of your app use:

dart
const reader = BarcodeReader(
  options: ReaderOptions(characterSet: CharacterSet.cp1251),
);

CharacterSet has 32 sets, from ISO-8859 and the Windows code pages to Shift_JIS, Big5, GB18030, EUC-KR and UTF-16. It applies only to codes that declare no character set.

Formats ​

The formats are a separate setting of the reader and of the controller, not an option: see Formats.