scanner library

The camera scanner: BarcodeScanner with templates and themes, its ScannerController, and the glass widgets to build your own scanner UI.

A layer on top of core.dart, content.dart and rendering.dart, which it exports too.

Classes

Barcode
A barcode found in an image or a camera frame.
BarcodeCaption
Text drawn with a barcode: BarcodeStyle.title above it, BarcodeStyle.caption under it. On screen and in the PNG and SVG exports alike.
BarcodeCapture
Barcodes found in one camera frame.
BarcodeCard
A rounded plate under a barcode and its text: BarcodeStyle.card.
BarcodeContent
The payload of a Barcode, parsed into a typed value.
BarcodeContentView
Shows a BarcodeContent as a barcode drawn with what its standard requires: a BarcodeView of its payload.
BarcodeError
Why a barcode was found but could not be decoded.
BarcodeImage
A created barcode as an 8-bit grayscale raster (0 = black, 255 = white).
BarcodeInput
What BarcodeWriter accepts for a format (BarcodeFormat.input): a description for a form field, an example that encodes, and the kind of keyboard.
BarcodeLabelSheet
Pages of labels to print: a code with its text on each label, in a fixed grid of columns x rows on paper.
BarcodeLabelSheetView
Shows one page of a BarcodeLabelSheet: white paper at the page's proportions, as wide as it may be, each code and caption where the PDF and SVG put them.
BarcodeListSheet
A sheet listing scanned codes with counts, the latest first and highlighted, and a "Done" button.
An image placed in the middle of a QR code.
BarcodeOutlines
Outlines the barcodes in ScannerLayout.barcodes in the theme's ScannerTheme.outlineColor and ScannerTheme.outlineWidth.
BarcodePosition
The four corners of a barcode, in pixels of the source image.
BarcodeReader
Reads barcodes from images: photos, files, screenshots, raw pixels.
BarcodeResultSheet
The result sheet of a scanned code: its kind ("LINK"), a title, details, the raw text, the symbology and buttons.
BarcodeScanner
A camera preview that scans barcodes.
BarcodeSequence
One symbol of a structured append sequence (a message split across several barcodes).
BarcodeStyle
How a barcode is drawn: by BarcodeView, and by toPng, toSvg, encodePng and encodeSvg when exported.
BarcodeSymbol
An encoded barcode: the module matrix plus what is needed to render it.
BarcodeThumbnail
The picture of a scanned barcode, for result sheets and lists of scans: the sharpest picture that is still exactly the code scanned.
BarcodeView
Shows a barcode. Drawn as vectors from the module matrix, so it is sharp at any size and pixel density.
BarcodeWriter
Creates barcodes from text or binary data.
BinaryContent
Binary data.
BoardingPassContent
An airline boarding pass (IATA Bar Coded Boarding Pass, Resolution 792): the passenger and one leg per flight.
BoardingPassLeg
One flight of a BoardingPassContent.
CollectedBarcode
A code in a BarcodeListSheet and how often it was scanned.
ContactContent
A contact card (vCard or MeCard).
ContentIssue
A problem that keeps BarcodeContent.toPayload from building a value, from BarcodeContent.validate.
CryptoContent
A cryptocurrency payment request: an address, optionally with an amount.
DriverLicenseContent
A North American driver's license or ID card (AAMVA DL/ID standard, the PDF417 on the back).
EmailContent
An e-mail draft (mailto:, MATMSG:, SMTP:).
EmvPaymentContent
An EMVCo merchant-presented QR code (EMV QRCPS): the format of PIX, PayNow, PromptPay, QRIS, VietQR, DuitNow and many other national schemes. 000201…6304XXXX.
EpcPaymentContent
A SEPA credit transfer (EPC QR code, "GiroCode", EPC069-12): BCD\n002\n1\nSCT\n…. Always in euros.
EsimContent
An eSIM activation code (LPA:1$smdp.example.com$MATCHING-ID, GSMA SGP.22): where the phone downloads the profile from.
EventContent
A calendar event (vEvent).
GeoContent
A location (geo:).
GostPaymentContent
A Russian bank transfer (ГОСТ Р 56042-2014): ST00012|Name=…|….
Gs1Content
GS1 data: Application Identifiers and their values.
OtpContent
A one-time password account for an authenticator app (otpauth://totp/Issuer:account?secret=…&issuer=Issuer, the Key URI format of Google Authenticator).
PaperSize
A sheet of paper, in millimetres.
PaymentContent
A payment request: who to pay, into which account, how much and what for. One subclass per standard, each with its own fields; the getters here are what every standard has, so that one screen can show any of them:
PhoneContent
A phone number to call (tel:, facetime:, facetime-audio:).
PickImageButton
A glass button that lets the user pick a photo and reads the codes in it with ScannerController.readImage: they are reported like the camera's.
PixelBuffer
Raw pixels to read barcodes from: a video frame, a frame from another camera plugin, a rendered widget, a decoded image.
ProductContent
A retail product number from an EAN-13, EAN-8, UPC-A or UPC-E barcode: the GTIN, and the ISBN or ISSN when the number is a book or a periodical (prefixes 978/979 and 977).
ReaderOptions
How thoroughly the engine searches an image.
ScanFieldButton
A button for a text field that fills it from a barcode: it opens a scanner in a sheet (scanBarcode), puts the code into controller and closes.
ScanLine
A line that runs across the scan window while the scanner searches, like the laser of a till scanner:
ScannerAction
A button of a BarcodeResultSheet.
ScannerActionButton
A full-width button of a result sheet: primary in the accent, or outlined.
ScannerActions
The buttons of a sheet: side by side when they fit, else stacked.
ScannerBadge
A rounded square with an icon in the accent, as next to a Wi‑Fi network's name.
ScannerButton
A 48 × 48 glass button with an icon, as on the scanner's corners.
ScannerChip
A chip with the symbology of a code ("QR Code", "GS1-128 · GS1").
ScannerCloseButton
A glass button that closes the scanner: by default it pops the current route.
ScannerController
Drives the camera of a BarcodeScanner and decodes its frames.
ScannerErrorView
Shown when the camera cannot be used: a card with what happened and the ways forward.
ScannerFields
Labelled values in a grid, such as the fields of a boarding pass.
ScannerGlass
A translucent panel over the camera: it blurs what is behind it (unless ScannerTheme.blur is off), has a light top edge and a soft shadow.
ScannerHint
A glass pill with an optional icon: hints ("Point at a QR code") and titles ("Pay with QR").
ScannerIcon
Draws a ScannerIconData.
ScannerIconData
An icon of the scanner widgets: a line icon drawn from SVG path data in a 24 × 24 box, or a glyph of an icon font (ScannerIconData.fromIconData). The built-in icons (ScannerIcons) are path data, so the scanner needs no icon font.
ScannerIcons
The icons of the scanner widgets.
ScannerIconSet
The icons the built-in scanner widgets draw, for a ScannerTheme's icons: each one given replaces the built-in icon, an icon left out (null) keeps it.
ScannerLayout
What an overlay needs to know, already in the coordinates of the BarcodeScanner widget.
ScannerLocalizations
The texts of the scanner widgets: button labels for screen readers, states, result sheets, the templates' titles and hints. Built in: English, Russian, German, Spanish, French and Chinese (simplified), chosen by the app's locale with no setup.
ScannerLocalizationsDe
The translations for German (de).
ScannerLocalizationsEn
The translations for English (en).
ScannerLocalizationsEs
The translations for Spanish Castilian (es).
ScannerLocalizationsFr
The translations for French (fr).
ScannerLocalizationsRu
The translations for Russian (ru).
ScannerLocalizationsZh
The translations for Chinese (zh).
ScannerOverlay
The default overlay: ScanWindowOverlay and BarcodeOutlines in the ScannerTheme of the scanner.
ScannerPlaceholder
Shown where the camera picture will be: while the camera starts, the scan window, its brackets breathing, a spinner and "Starting the camera…", so the layout does not jump when the picture arrives. While the camera is stopped (starting false), the scan window alone.
ScannerResult
A code the scanner found and shows, for a ScannerResultBuilder and a ScannerActionsBuilder.
ScannerScope
Gives the scanner widgets below it a theme and texts.
ScannerSheet
A sheet of strong glass at the bottom of the scanner, for results: in the theme's ScannerTheme.sheetColor and ScannerTheme.sheetBorder (ScannerTheme.sheet and ScannerTheme.sheetRadius).
ScannerState
The camera state of a ScannerController.
ScannerTemplate
A ready-made scanner screen: which buttons it has, where the scan window is, what happens when a code is found, and its default theme.
ScannerTextStyles
Changes to the scanner's text styles, each merged onto the built-in style: set only what you change, such as a size or a weight, and the rest stays, the font included.
ScannerTheme
Colors and shapes of the scanner widgets: the scan window, the buttons, the glass panels and the result sheets.
ScanVerdict
The answer of a ScannerCheck: its kind and what to tell the user.
ScanWindow
The part of the camera preview that is decoded, relative to what the user sees on screen. The default overlay draws exactly this area.
ScanWindowOverlay
Dims the camera outside the scan window and draws the window's corner brackets.
SmartHomeContent
A smart home device's setup code: Matter (MT:…) or HomeKit (X-HM://…), from the label on the device or its box.
SmsContent
A text message draft (sms:, smsto:, mms:, mmsto:).
SpaydPaymentContent
A Czech payment (Short Payment Descriptor, SPAYD): SPD*1.0*ACC:CZ…*AM:480.50*CC:CZK*MSG:….
SwissAddress
An address on a Swiss QR-bill.
SwissQrBillContent
A Swiss QR-bill (Swiss Payment Standards, version 2.3): SPC\n0200\n1\n….
SwitchCameraButton
A glass button that switches between the back and the front camera; hidden when there is no camera to switch to (ScannerState.canSwitchCamera).
TextContent
Plain text, or anything not recognised as a more specific type.
TorchButton
A glass button that turns the torch on and off; hidden when the camera has no torch. Its icons are the theme's icons.torchOn and icons.torchOff.
UpiPaymentContent
An Indian UPI payment: upi://pay?pa=name@bank&pn=…&am=….
UrlContent
A web address.
VinContent
A vehicle identification number (ISO 3779): 17 characters, from the Code 39 or Data Matrix on a windshield, door pillar or title.
VisibleBarcode
A barcode in view, positioned in the scanner widget.
WifiContent
Wi-Fi network credentials (WIFI: format).
WifiDppContent
A Wi-Fi Easy Connect (DPP) bootstrapping code: DPP:K:…;; on a router or a smart device, which a phone scans to put the device on its network.
ZoomButtons
Glass zoom presets; hidden when there are fewer than two. On an iPhone with several cameras on the back they are its cameras: "0.5×" (the ultra-wide camera, ScannerState.minZoom), "1×" and the telephoto camera (ScannerState.telephotoZoom, "4×" on an iPhone 17 Pro). Elsewhere "1×", "2×" and "4×", as far as the camera zooms, after ScannerState.minZoom when it is below 1 (an Android camera that zooms out). A preset selected after pinching shows the actual zoom ("1.6×").

Enums

AutoZoomState
Whether the scanner picks the lens and zoom by itself.
BarcodeContentType
How the payload of a Barcode should be interpreted.
BarcodeErrorKind
The kind of a BarcodeError.
BarcodeFormat
A barcode symbology, or a specific variant of one.
Binarizer
How an image is turned into black and white before detection.
CallType
How a PhoneContent calls.
CameraFacing
Which camera to use.
CameraResolution
Camera resolution. Higher resolutions read smaller and denser codes but decode each frame more slowly.
CaptureSource
Where the barcodes of a BarcodeCapture came from.
CharacterSet
A character set for ReaderOptions.characterSet.
ContactFormat
How ContactContent.toPayload writes a contact.
ContentIssueKind
What kind of problem a ContentIssue is, so that a form can say it in its own language.
CryptoCurrency
The network of a CryptoContent.
DetectionMode
When a ScannerController reports a barcode.
EanAddOn
What to do with EAN-2/EAN-5 add-on symbols (see ReaderOptions.eanAddOn).
EmvScheme
The national payment scheme of an EmvPaymentContent, from the globally unique identifier of its merchant account.
ErrorCorrection
Error correction level: how much of the symbol can be damaged and still read. Higher levels make the symbol larger.
FinderShape
Shape of the finder patterns ("eyes") of a QR code.
LinkService
Services with well-known links: messengers, social networks, music, app stores and maps.
LinkServiceInput
What LinkService.link takes for a service.
ModuleShape
Shape of the data modules of QR, Aztec and Data Matrix codes. Linear barcodes and PDF417 always use plain bars and rows.
OtpAlgorithm
The hash function of an OtpContent.
OtpType
How an OtpContent counts.
PixelLayout
Byte layout of the pixels in a PixelBuffer.
ResultHeader
What a BarcodeResultSheet shows next to its title.
ScanFeedback
What happened to a code, for ScannerTemplate.onFeedback to play a sound or haptic of your own.
ScanLineStyle
How a ScanLine moves.
ScannerButtonShape
Shape of the scanner's buttons and panels.
ScannerControlsLayout
Where a ScannerTemplate puts its controls: the photo button, the zoom presets, the camera switch, and the torch with ScannerTorchPosition.withControls. Each layout keeps them clear of the scan window and the hint: where it has no room, the controls take their adaptive place. They hide under a result sheet.
ScannerMode
What a ScannerTemplate does with the codes it finds.
ScannerPresentation
How scanBarcode shows its scanner.
ScannerStatus
What a ScannerController is doing.
ScannerTone
The color of a ScannerChip or a ScannerBadge.
ScannerTorchPosition
Where a ScannerTemplate puts its torch button.
ScannerWindowShape
Shape of the scan window as drawn. The camera is decoded in the window's rectangle whatever its shape.
ScanVerdictKind
How a ScannerCheck judged a code: the constructor of its ScanVerdict.
SmartHomePlatform
The smart home standard of a SmartHomeContent.
SwissReferenceType
The kind of reference on a Swiss QR-bill, from SwissQrBillContent.referenceType.
TorchState
Torch availability and state.
VinRegion
Where a vehicle was made, from the first character of its VIN. Its name for people, in the language of the scanner's texts: ScannerLocalizations.of(context).vinRegionOf(region).
WifiSecurity
Security of a Wi-Fi network.

Extensions

BarcodeContentOf on Barcode
barcode.content: the payload parsed into a typed value. Lives in the content layer, so the core Barcode does not depend on parsing.
BarcodeStyleContent on BarcodeStyle
style.encodeContent(content): a BarcodeContent encoded for a BarcodeStyle.
BarcodeWriterContent on BarcodeWriter
writer.encodeContent(content): encodes a BarcodeContent the way its kind needs. Lives in the content layer, so the core writer does not depend on it.
ScannerLocalizationsContent on ScannerLocalizations
Texts made of content, on top of the generated messages.

Constants

zxingCppVersion → const String
The zxing-cpp version inside the engine.

Functions

acceptOnly<T extends BarcodeContent>({ScanVerdict? reject}) → ScannerCheck
A ScannerCheck that accepts only content of the kind T and refuses the rest with reject (by default ScannerLocalizations.rejected).
openScanner<T>(BuildContext context, {ScannerTemplate template = const ScannerTemplate.minimal(), ScannerPresentation presentation = ScannerPresentation.page, ScannerTheme? theme, ScannerLocalizations? texts}) → Future<T?>
Opens template as a screen of its own, with its result sheet, and returns what the sheet passes to ScannerResult.finish, or null if the user closes it. For a code that needs more than scanBarcode gives, such as the customer a loyalty card belongs to:
scanBarcode(BuildContext context, {Set<BarcodeFormat>? formats, ScanWindow? scanWindow, CameraFacing? facing, String? hint, ScannerCheck? check, ScannerPresentation presentation = ScannerPresentation.page, ScannerTemplate? template, ScannerTheme? theme, ScannerLocalizations? texts}) → Future<Barcode?>
Opens a scanner and returns the first barcode found (and accepted by check), or null if the user closes it.
scanContent<T extends BarcodeContent>(BuildContext context, {Set<BarcodeFormat>? formats, ScanWindow? scanWindow, CameraFacing? facing, String? hint, ScanVerdict? reject, ScannerPresentation presentation = ScannerPresentation.page, ScannerTemplate? template, ScannerTheme? theme, ScannerLocalizations? texts}) → Future<T?>
Opens a scanner that accepts only content of the kind T, such as an OtpContent or a WifiContent, and returns it, or null if the user closes the scanner. Other codes are refused with reject (by default ScannerLocalizations.rejected) and the scanner stays open. The other parameters are those of scanBarcode.
warmUpBarcodeEngine({bool scanner = true}) → Future<void>
Starts the barcode engine ahead of time, e.g. in main(), so that the first scan or read does not wait for it.

Typedefs

ScannerActionsBuilder = List<ScannerAction> Function(BuildContext context, ScannerResult result)
Builds the buttons of the default result sheet, such as [...result.defaultActions, ScannerAction(label: 'Open', ...)].
ScannerCheck = FutureOr<ScanVerdict?> Function(Barcode barcode)
Decides whether the scanner accepts barcode: a ticket at the door, a sign-in code of your own service, a value for a form field.
ScannerOverlayBuilder = Widget Function(BuildContext context, ScannerLayout layout)
Builds what is drawn over the camera preview.
ScannerPickCallback = void Function(Barcode barcode, BarcodeCapture capture)
Called with the barcode the user picked in ScannerMode.pick and the capture it came from, which also holds the other codes found with it and gives its picture with capture.snapshot(barcode).
ScannerResultBuilder = Widget? Function(BuildContext context, ScannerResult result)
Builds the sheet shown for a code the scanner found: see ScannerResult. Return null for the default sheet, such as for a code of another kind than the one your sheet shows:

Exceptions / Errors

BarcodeWriteException
The data cannot be encoded in the requested format (e.g. letters in an EAN-13, or too much data for the chosen symbol version).
CameraFailureException
The camera failed: the platform reported an error not covered by the other ScannerExceptions, or the barcode engine kept failing.
CameraInUseException
The camera is busy: another app (or another part of this app) is using it. Trying again may work once it is released.
CameraNotFoundException
The device has no camera with the requested facing.
CameraPermissionException
The user denied camera access (or it is restricted by the system).
CameraUnsupportedException
Cameras cannot be used here at all: a web page that is not served over https (or from localhost), a browser without camera access, a platform without a camera plugin. Trying again does not help.
EngineException
The barcode engine could not do a call: it failed to start, stopped (shut down, or crashed), ran out of memory or failed inside. After it failed to start or stopped, the next call starts it again; after an error inside a call it keeps running, and the same input may fail the same way.
ImageDecodeException
The input is not an image the engine can decode (corrupt file, an unsupported format, or not an image at all).
ScannerException
A camera problem reported by the scanner in ScannerState.error.
ZxingException
Base class of every exception thrown by flutter_zxing 4.