BarcodeScannerWidget class

A generic, reusable barcode scanner widget.

This widget provides camera-based barcode scanning with customizable configuration options. It supports dark/light themes automatically and can be used in any context without inventory-specific dependencies.

The widget now supports up to 3 customizable action buttons that can be displayed alongside the camera preview. Use actionButtons to configure the buttons, or set enableActionButtons to false to hide them completely.

Example usage (basic):

BarcodeScannerWidget(
  onBarcodeDetected: (barcode) {
    print('Scanned: $barcode');
  },
  config: BarcodeScannerConfig(
    enableFlash: true,
    enableZoom: true,
    scanAreaSize: 200,
  ),
)

Example usage (with action buttons):

BarcodeScannerWidget(
  onBarcodeDetected: (barcode) => print('Scanned: $barcode'),
  enableActionButtons: true,
  actionButtons: [
    BarcodeScannerActionButton.search(
      onTap: () => print('Search tapped'),
      title: 'Tap to search',
      triggerImmediately: true,
    ),
    BarcodeScannerActionButton.reset(
      onTap: () => print('Reset tapped'),
    ),
  ],
)
Inheritance

Constructors

BarcodeScannerWidget({Key? key, required dynamic onBarcodeDetected(String), BarcodeScannerConfig config = const BarcodeScannerConfig(), BarcodeScannerController? controller, VoidCallback? onPermissionDenied, Widget? permissionDeniedWidget, Color? lineColor, Color? cooldownLineColor, Color? outOfFocusLineColor, double? height, double? minHeight, double? maxHeight, BorderRadius? borderRadius, double? zoomAreaIdleOpacity, double? zoomAreaActiveOpacity, int? zoomAreaOpacityTimeoutSeconds, bool enableActionButtons = false, List<BarcodeScannerActionButton>? actionButtons, ValueChanged<BarcodeScannerMode>? onModeChanged, BarcodeScannerMode initialMode = BarcodeScannerMode.camera, double actionButtonsSpacing = 8.0, bool attachActionButtonsToCamera = true, Color? cameraModeActiveBackgroundColor, Color? cameraModeActiveIconColor, Color? cameraModeInactiveBackgroundColor, Color? cameraModeInactiveIconColor, @Deprecated('Use actionButtons instead') BarcodeSideActionConfig? sideActionConfig, @Deprecated('Use cameraModeInactiveBackgroundColor instead') Color? cameraModeBackgroundColor, @Deprecated('Use cameraModeInactiveIconColor instead') Color? cameraModeIconColor, @Deprecated('Use lineColor instead') Color? borderColor, @Deprecated('Use cooldownLineColor instead') Color? cooldownBorderColor, @Deprecated('Use outOfFocusLineColor instead') Color? outOfFocusBorderColor})
const

Properties

actionButtons List<BarcodeScannerActionButton>?
List of action buttons to display alongside the camera. Maximum of 3 buttons are supported. Buttons are displayed in the order provided. Each button can have its own icon, title, callback, and styling.
final
actionButtonsSpacing double
The spacing between camera and action buttons area. Only applied between the camera mode button and action area in action mode. In camera mode, buttons are attached directly to the camera area.
final
attachActionButtonsToCamera bool
Whether to attach action buttons directly to the camera area (no spacing). When true, action button corners will be adjusted for visual continuity. Defaults to true.
final
borderColor Color?
final
borderRadius BorderRadius?
The border radius for the scanner container. Defaults to BorderRadius.circular(8).
final
cameraModeActiveBackgroundColor Color?
Background color for the camera mode button when camera is active.
final
cameraModeActiveIconColor Color?
Icon color for the camera mode button when camera is active.
final
cameraModeBackgroundColor Color?
@Deprecated Use cameraModeInactiveBackgroundColor instead.
final
cameraModeIconColor Color?
@Deprecated Use cameraModeInactiveIconColor instead.
final
cameraModeInactiveBackgroundColor Color?
Background color for the camera mode button when in action mode (inactive).
final
cameraModeInactiveIconColor Color?
Icon color for the camera mode button when in action mode (inactive).
final
config BarcodeScannerConfig
Configuration options for the scanner.
final
controller BarcodeScannerController?
Optional controller for external control of the scanner.
final
cooldownBorderColor Color?
final
cooldownLineColor Color?
Custom color for the scanning line when in cooldown.
final
enableActionButtons bool
Whether to enable action buttons alongside the camera. When true, action buttons defined in actionButtons will be displayed. Defaults to false for backwards compatibility.
final
hashCode int
The hash code for this object.
no setterinherited
height double?
The height of the scanner container. When using minHeight and maxHeight, this value is used as the initial/preferred height. If null, the widget will expand to fill available space.
final
initialMode BarcodeScannerMode
Initial mode of the scanner. Defaults to camera mode.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
lineColor Color?
Custom color for the scanning line (default: red).
final
maxHeight double?
The maximum height constraint for the scanner area. When set, the widget will use ConstrainedBox with this maximum height.
final
minHeight double?
The minimum height constraint for the scanner area. When set, the widget will use ConstrainedBox with this minimum height.
final
onBarcodeDetected → dynamic Function(String)
Callback triggered when a barcode is successfully detected.
final
onModeChanged ValueChanged<BarcodeScannerMode>?
Callback when the mode changes between camera and action modes.
final
onPermissionDenied VoidCallback?
Optional callback for permission denied state.
final
outOfFocusBorderColor Color?
final
outOfFocusLineColor Color?
Custom color for the scanning line when barcode is out of focus area.
final
permissionDeniedWidget Widget?
Custom widget to display when permission is not granted.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sideActionConfig BarcodeSideActionConfig?
@Deprecated Use actionButtons instead. Configuration for the side action area (backwards compatibility).
final
zoomAreaActiveOpacity double?
The opacity of the zoom control area when active (user interacting). Value should be between 0.0 (fully transparent) and 1.0 (fully opaque). If null, uses the value from BarcodeScannerConfig.zoomAreaActiveOpacity.
final
zoomAreaIdleOpacity double?
The opacity of the zoom control area when idle (not interacting). Value should be between 0.0 (fully transparent) and 1.0 (fully opaque). If null, uses the value from BarcodeScannerConfig.zoomAreaIdleOpacity.
final
zoomAreaOpacityTimeoutSeconds int?
Duration in seconds after which the zoom area returns to idle opacity. If null, uses the value from BarcodeScannerConfig.zoomAreaOpacityTimeoutSeconds.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<BarcodeScannerWidget>
Creates the mutable state for this widget at a given location in the tree.
override
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