omni_qrcode_barcode_web_reader 0.0.2-beta
omni_qrcode_barcode_web_reader: ^0.0.2-beta copied to clipboard
A QrCode and Barcode web reader
Omni QR Code / Barcode Web Reader #
A Flutter widget for web applications to scan QR codes and various barcode formats using the device's camera via JavaScript interoperability.
This package leverages the browser's getUserMedia API to access the camera and uses the ZXing-JS library for decoding barcodes and QR codes.
Features #
- Access camera stream on Flutter Web.
- Decode QR codes and common barcode formats (powered by ZXing-JS).
- Callback on successful detection (
onDetect). - Callback for errors (
onError) like permission denial or camera issues. - Customizable overlay to guide the user:
- Dimmed background outside the scanning area.
- Clear scanning area (cutout).
- Selectable overlay shapes optimized for QR Codes or Barcodes (
ScanMode).
- Optional placeholder widget during camera initialization.
Parameters #
-
onDetect: Callback function whenever the scan works;
Funtion(BarcodeResult result) { } -
onError: Callback function whenever the scan fails;
Funtion?(String? error) { } -
height: Scanner vertical size;
-
width: Scanner horizontal size;
-
placeholder: Widget shown while scanner is initializing;
-
fit: Scanner boxfit property to adjust its content to given size
-
scanMode: Scanner modes to switch custom overlay.
ScanMode.Barcode ScanMode.QrCode
Platform Support #
- ✅ Flutter Web Only
- ✅ Dart >= 3.6.0
This package relies heavily on web-specific APIs (navigator.mediaDevices, HtmlElementView) and JavaScript interoperability, so it will not work on mobile or desktop platforms.
Getting Started #
1. Installation #
Add the package to your pubspec.yaml:
dependencies:
flutter:
sdk: flutter
omni_qrcode_barcode_web_reader: ^latest # Check pub.dev for the latest version
js: ^0.6.7 # Or latest JS interop package version
2. Setup #
Add the ZXing-JS library script tag inside the section of your web/index.html. Using a CDN is the simplest way:
<!-- web/index.html -->
<!DOCTYPE html>
<html>
<head>
<!-- ... other head elements ... -->
<title>My Scanner App</title>
<!-- ADD ZXing-JS Library -->
<script type="text/javascript" src="https://unpkg.com/@zxing/library@latest/umd/index.min.js"></script>
<!-- ... other head elements ... -->
</head>
<body>
<!-- Flutter app script will be here -->
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>
Add the scan.js script
<!-- web/index.html -->
<!DOCTYPE html>
<html>
<head>
<!-- ... other head elements ... -->
<title>My Scanner App</title>
<!-- ADD the Interop JS file -->
<script src="barcode_scanner.js" defer></script>
<!-- ... other head elements ... -->
</head>
<body>
<!-- Flutter app script will be here -->
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>