SimpleBarcodeScanner class

A utility class for barcode scanning functionality. Can be used both as a widget and through static methods.

Example usage as a widget:

SimpleBarcodeScanner(
  onScanned: (code) {
    print('Scanned: $code');
  },
  continuous: true,
)

Example usage as static method:

final result = await SimpleBarcodeScanner.scanBarcode(context);
Inheritance

Constructors

SimpleBarcodeScanner({double? scaleWidth, double? scaleHeight, Key? key, String lineColor = "#ff6666", bool isShowFlashIcon = false, ScanType scanType = ScanType.barcode, CameraFace cameraFace = CameraFace.back, int? delayMillis, Widget? child, dynamic onScanned(String)?, bool continuous = false, VoidCallback? onClose, ScanFormat scanFormat = ScanFormat.ALL_FORMATS, required BarcodeScannerViewCreated onBarcodeViewCreated})
Creates a new SimpleBarcodeScanner widget.
const

Properties

cameraFace CameraFace
Which camera to use for scanning.
final
child Widget?
Optional widget to display in the scanner interface.
final
continuous bool
Whether to continuously scan barcodes (true) or stop after first scan (false).
final
delayMillis int?
Delay in milliseconds between consecutive scans.
final
hashCode int
The hash code for this object.
no setterinherited
isShowFlashIcon bool
Whether to show the flash toggle icon.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
lineColor String
The color of the scanning line in hex format.
final
onBarcodeViewCreated BarcodeScannerViewCreated
Callback function called when the scanner view is created.
final
onClose VoidCallback?
Callback function called when the scanner is closed.
final
onScanned → dynamic Function(String)?
Callback function called when a barcode is successfully scanned. Provides the scanned string value.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scaleHeight double?
The height of the scanner view.
final
scaleWidth double?
The width of the scanner view.
final
scanFormat ScanFormat
The format of the barcode to scan. Default is ALL_FORMATS (e.g., ONLY_QR_CODE, ONLY_BARCODE). Only works on Android and iOS. Web will scan all formats.
final
scanType ScanType
The type of barcode to scan (e.g., barcode, QR code).
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

scanBarcode(BuildContext context, {String lineColor = "#ff6666", String cancelButtonText = "Cancel", bool isShowFlashIcon = false, ScanType scanType = ScanType.barcode, CameraFace cameraFace = CameraFace.back, BarcodeAppBar? barcodeAppBar, int? delayMillis, Widget? child, ScanFormat scanFormat = ScanFormat.ALL_FORMATS}) Future<String?>
Launches the barcode scanner interface and returns the scanned value.
streamBarcode(BuildContext context, {String lineColor = "#ff6666", String cancelButtonText = "Cancel", bool isShowFlashIcon = false, ScanType scanType = ScanType.barcode, CameraFace cameraFace = CameraFace.back, BarcodeAppBar? barcodeAppBar, int? delayMillis, ScanFormat scanFormat = ScanFormat.ALL_FORMATS, Widget? child}) Stream<String>
Continuously scans barcodes and emits results through a stream.