ScanKitController class

Controller for the embedded ScanKitView

Manages the scanner lifecycle and provides:

Basic Usage

final controller = ScanKitController(
  formats: [BarcodeFormat.qr],
  onDetect: (barcode) => print(barcode.value),
);

// Use with ScanKitView
ScanKitView(controller: controller)

// Control the scanner
await controller.toggleTorch();
await controller.setZoom(2.0);

// Don't forget to dispose
controller.dispose();
Inheritance

Constructors

ScanKitController({List<BarcodeFormat>? formats, void onDetect(BarcodeResult barcode)?, void onScanError(ScanKitException error)?, bool validator(BarcodeResult barcode)?, CameraFacing cameraFacing = CameraFacing.back, CameraResolution resolution = CameraResolution.high, bool invertColors = false, ScanRegion? scanRegion, int debounceMs = 500, bool autoZoom = false})

Properties

autoZoom bool
Whether to auto-zoom toward detected barcodes
getter/setter pair
barcodes Stream<BarcodeResult>
Stream of detected barcodes (after validation passes)
no setter
cameraFacing CameraFacing
Which camera to use (front or back)
getter/setter pair
cameraFacingState ValueListenable<CameraFacing>
Current camera facing direction
no setter
debounceMs int
Debounce delay in milliseconds between same-value detections
getter/setter pair
errors Stream<ScanKitException>
Stream of errors from the scanner
no setter
formats List<BarcodeFormat>?
Barcode formats to scan for (null = all formats)
final
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
invertColors bool
Whether to invert colors for white-on-black barcodes
getter/setter pair
onDetect → void Function(BarcodeResult barcode)?
Callback when a barcode is detected (after validation passes)
final
onScanError → void Function(ScanKitException error)?
Callback when an error occurs
final
resolution CameraResolution
Camera resolution preset
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scanRegion ScanRegion?
Region of interest for scanning (null = full frame)
getter/setter pair
torchState ValueListenable<bool>
Current torch state
no setter
validator bool Function(BarcodeResult barcode)?
Optional validator - return false to reject the barcode
final
zoomLevel ValueListenable<double>
Current zoom level
no setter

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
override
isTorchAvailable() Future<bool>
Check if torch is available
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
onBarcodeDetected(BarcodeResult barcode) → void
Called when a barcode is detected in embedded scanner mode
onCameraSwitched(CameraFacing facing) → void
Called when camera is switched
onError(String code, String message) → void
Called when an error occurs
onTorchStateChanged(bool enabled) → void
Called when torch state changes
onZoomChanged(double zoom) → void
Called when zoom level changes
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
setTorch(bool enabled) Future<void>
Set torch state explicitly
setZoom(double zoom) Future<void>
Set zoom level (1.0 = no zoom)
switchCamera() Future<void>
Switch between front and back camera
toggleTorch() Future<void>
Toggle the torch on/off
toString() String
A string representation of this object.
inherited
updateConfig({List<BarcodeFormat>? formats, CameraFacing? cameraFacing, CameraResolution? resolution, bool? invertColors, ScanRegion? scanRegion, int? debounceMs, bool? autoZoom}) Future<void>
Update scanner configuration at runtime

Operators

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