flutter_zxing library

Reads and creates barcodes on Android, iOS, macOS, Linux, Windows and the web, with zxing-cpp.

The 4.0 API: BarcodeReader, BarcodeWriter, BarcodeScanner. The 3.x API (zx, ReaderWidget, WriterWidget) is deprecated and keeps working, on the same engine, until 5.0.

Classes

Barcode
A barcode found in an image or a camera frame.
BarcodeCapture
Barcodes found in one camera frame.
BarcodeContent
The payload of a Barcode, parsed into a typed value.
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.
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 accent color.
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 BarcodeSymbol.toPng and BarcodeSymbol.toSvg 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.
CameraController
Controls a device camera.
CameraImage
A single complete image buffer from the platform camera.
Code
CodeHitRegion
A detected code together with the on-screen rect it occupies.
Codes
CollectedBarcode
A code in a BarcodeListSheet and how often it was scanned.
ContactContent
A contact card (vCard or MeCard).
DecodeParams
EmailContent
An e-mail draft (mailto:, MATMSG:, SMTP:).
Encode
EncodeParams
EventContent
A calendar event (vEvent).
Format
GeoContent
A location (geo:).
Gs1Content
GS1 data: Application Identifiers and their values.
ImageFormat
Pixel formats accepted by the decoder, mirroring ZXing::ImageFormat.
Messages
MultiResultOverlay
MultiScanPainter
PhoneContent
A phone number (tel:).
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.
Position
Represents the position of a barcode in an image.
ReaderOptions
How thoroughly the engine searches an image.
ReaderWidget
Widget to scan a code from the camera stream
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 · ]Q1").
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
A line icon of the scanner widgets, drawn from SVG path data in a 24 × 24 box. The scanner draws its own icons, so it needs no icon font.
ScannerIcons
The icons of the scanner widgets.
ScannerLayout
What an overlay needs to know, already in the coordinates of the BarcodeScanner widget.
ScannerOverlay
The default overlay: ScanWindowOverlay and BarcodeOutlines in the ScannerTheme of the scanner.
ScannerOverlayBorder
Universal border for a scanner overlay with a transparent cut-out. cutOutSize > 1 — size in pixels, <= 1 — percentage of the smaller side. Offsets: -1.0..1.0 (left/right, up/down).
ScannerPlaceholder
Shown 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.
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.
ScannerState
The camera state of a ScannerController.
ScannerStrings
The texts of the scanner widgets: button labels for screen readers, states, result sheets. English by default; pass your translations to BarcodeScanner(strings: ...):
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.
ScannerTheme
Colors and shapes of the scanner widgets: the scan window, the buttons, the glass panels and the result sheets.
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.
SmsContent
A text message draft (sms:, smsto:, mms:, mmsto:).
SwitchCameraButton
A glass button that switches between the back and the front camera.
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.
UrlContent
A web address.
VisibleBarcode
A barcode of the latest capture, positioned in the scanner widget.
WifiContent
Wi-Fi network credentials (WIFI: format).
WriterWidget
Widget to create a code from a text and barcode format
XFile
A CrossFile is a cross-platform, simplified File abstraction.
ZoomButtons
Glass zoom presets ("0.5×", "1×", "2×", "4×") for the levels the camera supports; hidden when it supports fewer than two. The widest level is ScannerState.minZoom when it is below 1 (an iPhone's ultra-wide camera, which also focuses close up). A level selected after pinching shows the actual zoom ("1.6×").
Zxing
The 3.x API behind zx.

Enums

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.
BarcodeThumbnailKind
How a BarcodeThumbnail pictures a barcode.
Binarizer
How an image is turned into black and white before detection.
CameraFacing
Which camera to use.
CameraLensDirection
The direction the camera is facing.
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.
CodeSource
DetectionMode
When a ScannerController reports a barcode.
EanAddOn
What to do with EAN-2/EAN-5 add-on symbols (see ReaderOptions.eanAddOn).
EccLevel
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.
ModuleShape
Shape of the data modules of QR, Aztec and Data Matrix codes. Linear barcodes and PDF417 always use plain bars and rows.
PixelLayout
Byte layout of the pixels in a PixelBuffer.
ResolutionPreset
Affect the quality of video recording and image capture:
ScannerButtonShape
Shape of the scanner's buttons and panels.
ScannerStatus
What a ScannerController is doing.
TorchState
Torch availability and state.
WifiSecurity
Security of a Wi-Fi network.

Constants

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

Properties

barcodeDemoText → Map<int, String>
final
barcodeMaxTextLengths → Map<int, int>
final
barcodeNames → Map<int, String>
final
barcodeRatios → Map<int, double>
final
zx → Zxing
The 3.x API: reads and creates barcodes.
final

Functions

cameraImageFormat(CameraImage image) → int
The pixel format to tell the decoder a camera frame is in, for DecodeParams.imageFormat.
codeHitRegions(List<Code> codes, Size size, {Offset offset = Offset.zero}) → List<CodeHitRegion>
Maps each code's Position onto the overlay's coordinate space.
convertImage(CameraImage image) → Future<Uint8List>
Extracts the bytes the decoder should scan from a camera frame.
pngFromBytes(Uint8List bytes, int width, int height) → Uint8List
Encodes a single-channel (grayscale) buffer as a PNG.
resizeToMaxSize(Image image, int? maxSize) → Image
Scales image down so that neither side exceeds maxSize, preserving the aspect ratio. Returns image untouched when maxSize is null or not positive, or when the image already fits.
rgbBytes(Image image) → Uint8List
Returns image as a tightly packed 8-bit RGB buffer of width * height * 3 bytes.
scanBarcode(BuildContext context, {Set<BarcodeFormat>? formats, ScanWindow? scanWindow, CameraFacing facing = CameraFacing.back, String? hint, ScannerTemplate? template, ScannerTheme? theme, ScannerStrings? strings}) → Future<Barcode?>
Opens a full-screen scanner and returns the first barcode found, or null if the user closes it.
tightlyPackedYPlaneFromCameraImage(CameraImage image) → Uint8List
Returns the luminance (Y) plane of image without its row padding.
warmUpBarcodeEngine() → 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, Barcode barcode, VoidCallback scanAgain)
Builds the buttons of the default result sheet for barcode.
ScannerOverlayBuilder = Widget Function(BuildContext context, ScannerLayout layout)
Builds what is drawn over the camera preview.
ScannerResultBuilder = Widget Function(BuildContext context, Barcode barcode, VoidCallback scanAgain)
Builds the sheet shown for a scanned barcode; scanAgain hides it and resumes scanning.

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: it is used by another app, or the platform reported an error.
CameraNotFoundException
The device has no camera with the requested facing.
CameraPermissionException
The user denied camera access (or it is restricted by the system).
EngineException
The engine failed to start or stopped unexpectedly. The next call starts it again.
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.