Code Monkey home page Code Monkey logo

flutter_zxing's Introduction

ZXScanner logo

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
  • Flashlight and pinch to zoom support

Todo

  • Return scanned barcode position and size
  • 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 FlutterZxing
// To read barcode from camera image directly
await FlutterZxing.startCameraProcessing(); // Call this in initState
cameraController?.startImageStream((image) async {
    CodeResult result = await FlutterZxing.processCameraImage(image);
    if (result.isValidBool) {
        debugPrint(result.textString);
    }
    return null;
});
FlutterZxing.stopCameraProcessing(); // Call this in dispose

// To read barcode from XFile, String or url
XFile xFile = XFile('Your image path');
CodeResult? resultFromXFile = await FlutterZxing.readImagePath(xFile);

String path = 'Your image path';
CodeResult? resultFromPath = await FlutterZxing.readImagePathString(path);

String url = 'Your image url';
CodeResult? resultFromUrl = await FlutterZxing.readImageUrl(url);

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 text = 'Text to encode';
final result = FlutterZxing.encodeBarcode(text, 300, 300, Format.QRCode, 10, 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.

flutter_zxing's People

Contributors

khoren93 avatar h1376h avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.