Skip to content

Flutter plugin for scanning and generating QR codes using the ZXing library, supporting Android, iOS, and desktop platforms

License

Notifications You must be signed in to change notification settings

iezed/flutter_zxing

Repository files navigation

ZXScanner logo

Download on the App Store Download on the Google Play

flutter_zxing

A barcode and QR code scanner based on ZXing C++ library natively in Flutter with Dart FFI.

Demo Screenshots

01_scanner_screen  02_creator_screen 

Supported Barcode Formats

1D product 1D industrial 2D
UPC-A Code 39 QR Code
UPC-E Code 93 DataMatrix
EAN-8 Code 128 Aztec
EAN-13 Codabar PDF417
DataBar ITF MaxiCode (beta)
DataBar Expanded

Features

  • Scan barcode from camera stream, image path or url
  • Scan multiple barcodes from camera stream, image path or url
  • Create barcode from text
  • Return scanned barcode position points
  • Flashlight and pinch to zoom support

Todo

  • Write tests

Getting Started

To read barcode:

import 'package:flutter_zxing/flutter_zxing.dart';

// Use ReaderWidget to quickly read barcode from camera image
@override
Widget build(BuildContext context) {
    return Scaffold(
        body: ReaderWidget(
            onScan: (result) async {
                // Do something with the result
            },
        ),
    ),
);

// Or use flutter_zxing plugin methods 
// To read barcode from camera image directly
await startCameraProcessing(); // Call this in initState
cameraController?.startImageStream((image) async {
    CodeResult result = await processCameraImage(image);
    if (result.isValidBool) {
        debugPrint(result.textString);
    }
    return null;
});
stopCameraProcessing(); // Call this in dispose

// To read barcode from XFile, String, url or Uint8List bytes
XFile xFile = XFile('Your image path');
CodeResult? resultFromXFile = await readBarcodeImagePath(xFile);

String path = 'Your local image path';
CodeResult? resultFromPath = await readBarcodeImagePathString(path);

String url = 'Your remote image url';
CodeResult? resultFromUrl = await readBarcodeImageUrl(url);

Uint8List bytes = Uint8List.fromList(yourImageBytes);
CodeResult? resultFromBytes = await readBarcode(bytes);

To create barcode:

import 'package:flutter_zxing/flutter_zxing.dart';
import 'dart:typed_data';
import 'package:image/image.dart' as imglib;

// Use WriterWidget to quickly create barcode
@override
Widget build(BuildContext context) {
    return Scaffold(
        body: WriterWidget(
            onSuccess: (result, bytes) {
                // Do something with the result
            },
            onError: (error) {
                // Do something with the error
            },
        ),
    ),
);

// Or use FlutterZxing to create barcode directly
final result = encodeBarcode(
    'Text to encode',
    format: Format.QRCode,
    width: 300,
    height: 300,
    margin: 10,
    eccLevel: 0,
);
if (result.isValidBool) {
    final img = imglib.Image.fromBytes(width, height, result.bytes);
    final encodedBytes = Uint8List.fromList(imglib.encodeJpg(img));
    // use encodedBytes as you wish
}

License

MIT License. See LICENSE.

About

Flutter plugin for scanning and generating QR codes using the ZXing library, supporting Android, iOS, and desktop platforms

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 60.1%
  • C++ 17.1%
  • CMake 8.9%
  • Swift 7.1%
  • Ruby 4.0%
  • C 0.8%
  • Other 2.0%