Skip to content
Blog

Barcode Scanning Packages in Flutter: EAN, Code 128, UPC, and More

Compare mobile_scanner and google_mlkit_barcode_scanning for 1D and 2D barcodes: format matrix, platform coverage, detection config, and code generation.

Published on • November 12, 2026

AI Assistant

QR codes get all the tutorials, but real products also need retail and logistics symbologies: EAN-13 on packaging, UPC-A at the checkout, Code 128 on shipping labels, PDF417 on boarding passes, Data Matrix on electronics. Scanning those is mostly the same camera plumbing, with a different format whitelist and a different decoder underneath. This post compares the packages and shows how to configure them for 1D work.

The format matrix

Formats split into two families, and the distinction drives both scanning speed and what you can render:

FamilyFormatsTypical use
1D linearEAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, ITF, CodabarRetail, warehouses, labels
2D matrixQR Code, Data Matrix, Aztec, PDF417Tickets, documents, payments

Narrowing to the formats you actually accept is the cheapest performance win: fewer decoders run per frame, and false positives from a Code 39 label you never wanted disappear.

Package comparison

PackageVersionPlatformsEngine
mobile_scanner7.5.0Android, iOS, macOS, webCameraX + ML Kit (Android), AVFoundation + Apple Vision (iOS/macOS), ZXing (web)
google_mlkit_barcode_scanning1.0.2Android, iOS onlyGoogle ML Kit via platform channels
qr_code_scanner and similarlegacynarrowerQR-focused, fewer features

mobile_scanner is the universal choice because it wraps a camera widget and a controller in one package, and it exposes features the raw ML Kit plugin does not: scanWindow, returnImage, analyzeImage, autoZoom, and lens switching. The google_mlkit_barcode_scanning route gives you direct control of ML Kit’s BarcodeScanner when you already have frames from another camera source, at the cost of writing your own InputImage conversion and camera lifecycle.

Configuring detection

Whitelist formats, throttle duplicates, and restrict the analysis region:

final controller = MobileScannerController(
  formats: const [
    BarcodeFormat.ean13,
    BarcodeFormat.upcA,
    BarcodeFormat.code128,
    BarcodeFormat.dataMatrix,
  ],
  detectionSpeed: DetectionSpeed.noDuplicates,
  detectionTimeoutMs: 500,
  autoTorch: false,
  facing: CameraFacing.back,
);

At 30 or more frames per second the same symbol fires onDetect repeatedly, so detectionTimeoutMs plus DetectionSpeed.noDuplicates is your throttle. Torch is await controller.toggleTorch(), or autoTorch: true on Android, iOS, and macOS. The scanWindow parameter analyzes only a rectangle in the middle of the frame, which cuts work on large screens; note it is unsupported on web.

Typed results and raw bytes

Both engines decode the payload, but they differ in what else you get. ML Kit returns a Barcode with type, format, boundingBox, cornerPoints, rawValue, rawBytes, and a typed value you can switch on: BarcodeWifi, BarcodeUrl, BarcodeEmail, BarcodePhone, BarcodeGeoPoint, BarcodeDriverLicense, and so on, with barcodeScanner.close() to release the detector.

mobile_scanner gives you a BarcodeCapture containing a list of Barcode, each with rawValue and rawBytes. One caveat from its readme: Apple Vision does not expose raw payload bytes directly, so rawBytes on iOS and macOS is reconstructed best-effort, and can come back null for Kanji-mode QR codes or payloads containing bytes in 0x80 to 0x9F. Android (ML Kit) supports rawBytes for all formats, and on web it depends on the active backend.

Web and desktop reality

On web, mobile_scanner picks a detection backend: native BarcodeDetector (Chrome, Edge, Safari 17+, not Firefox), zxing-wasm (~2 MB from a CDN, works everywhere including Firefox), or the legacy pure-JS ZXing. Start scanning from a user gesture, and expect the first detection to be slower while the WASM loads. Linux and Windows have no support in either package: use a USB scanner in keyboard mode, a web build, or a platform channel to a native decoder.

Generating and printing codes

Scanning is half the loop. barcode_widget (2.0.4) sits on the barcode library (2.2.4) and renders any supported symbology as a widget across all six platforms:

BarcodeWidget(
  barcode: Barcode.ean13(),
  data: '4006381333931',
  width: 220,
  height: 90,
  errorBuilder: (context, error) => Text('Invalid EAN-13: $error'),
)

For labels or PDFs, use the underlying barcode package directly to paint SVG paths or draw on a Canvas. EAN-13 validates its checksum and rejects bad input, which is exactly why errorBuilder exists; for QR codes with a logo overlay, raise Barcode.qrCode(errorCorrectLevel: BarcodeQRCorrectionLevel.high) so the error correction still reads.

Common pitfalls

  • Leaving the default formats open, wasting battery decoding symbols you will reject anyway.
  • Forgetting NSCameraUsageDescription on iOS or the camera permission on Android, which fails before any decoding starts.
  • Not stopping the scanner on lifecycle changes, so the camera keeps running behind other apps.
  • Parsing rawValue without validating the EAN-13 or UPC check digit, so bad reads reach your product lookup.
  • Assuming every format reads at the same distance: 1D symbols need the bars to fill the frame, so guide users with the scan window instead of relying on autofocus.
  • Scanning a symbol type you never whitelisted and rejecting it in onDetect, which burns battery for nothing.
  • Expecting analyzeImage or scanWindow on web, where both are unsupported.
  • Assuming rawBytes is always populated on Apple platforms; check for null and fall back to rawValue.
  • Using ML Kit’s bundled model on size-sensitive builds: dev.steenbakker.mobile_scanner.useUnbundled=true in android/gradle.properties drops roughly 3 to 10 MB for a ~600 KB on-demand download.

The existing QR scanning post covers camera permissions, lifecycle pausing, and deduplication in detail, and the Firebase ML integration post shows the same InputImage pipeline for text recognition if you need OCR alongside barcode reads.

Takeaway: Pick mobile_scanner for a camera-first scanner with format whitelists, throttling, torch, and web support, drop to google_mlkit_barcode_scanning when you already own the frame pipeline and want ML Kit’s typed values, and pair either with barcode_widget so the same app can render the EAN-13, Code 128, or Data Matrix codes it reads.

Sources