BarcodeScanner class
A camera preview that scans barcodes.
BarcodeScanner(onDetect: (capture) => print(capture.barcode.text))
Without a controller it creates one and disposes it with the widget; pass your own to configure formats, the scan window or detection, and to control the camera.
By default it dims the camera around the scan window, whose brackets lock onto the code found, and outlines the codes. A template adds a whole screen around it: buttons, hints and a result sheet:
BarcodeScanner(
template: ScannerTemplate.minimal(),
theme: ScannerTheme(accent: Color(0xFFFF6A1A)),
)
Replace the overlay with overlayBuilder, or add your own buttons over it with foregroundBuilder. Tap to focus and pinch to zoom are on.
While the scanner is not shown, such as under another page or in a tab that is not selected (TickerMode off), it stops decoding, and after a few seconds releases the camera; see pauseWhenHidden.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- BarcodeScanner
Constructors
-
BarcodeScanner({Key? key, ScannerController? controller, ValueChanged<
BarcodeCapture> ? onDetect, ScannerTemplate? template, ScannerTheme? theme, ScannerStrings? strings, ScannerOverlayBuilder? overlayBuilder, ScannerOverlayBuilder? foregroundBuilder, Widget errorBuilder(BuildContext context, ScannerException error)?, WidgetBuilder? placeholderBuilder, VoidCallback? onOpenSettings, BoxFit fit = BoxFit.cover, bool tapToFocus = true, bool pinchToZoom = true, bool pauseWhenHidden = true}) -
Creates a scanner.
const
Properties
- controller → ScannerController?
-
The controller.
nullcreates one with the template's scan window, formats and detection, or with default settings.final - errorBuilder → Widget Function(BuildContext context, ScannerException error)?
-
Shown instead of the preview when the camera cannot be used. Default
ScannerErrorView.
final
- fit → BoxFit
-
How the preview fills the widget. With BoxFit.cover (the default)
the edges of the camera image may be cut off; the scan window and
barcode outlines always match what is visible.
final
- foregroundBuilder → ScannerOverlayBuilder?
-
Builds a layer of your own over the overlay (the template's too),
in every state of the camera (ScannerLayout.state), with the
scanner's theme: buttons of your own beside the template's.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
onDetect
→ ValueChanged<
BarcodeCapture> ? -
Called for every capture the controller reports.
final
- onOpenSettings → VoidCallback?
-
Opens the app's settings, where the user allows the camera: the
default error view (and the template's) then offers "Open Settings"
when camera access is off, instead of "Try again". Opening the
settings needs a plugin such as
app_settings; default ScannerTemplate.onOpenSettings.final - overlayBuilder → ScannerOverlayBuilder?
-
Builds the overlay while the camera runs, instead of the template's
or the default ScannerOverlay. Return
const SizedBox.shrink()for none.final - pauseWhenHidden → bool
-
While the scanner is not shown (TickerMode off: under another
page, in a tab that is not selected), pause decoding, and release the
camera after a few seconds; when it shows again, go on as before.
Nothing is reported to
onDetectmeanwhile.falsekeeps the camera as it is.final - pinchToZoom → bool
-
Zoom with a pinch gesture.
final
- placeholderBuilder → WidgetBuilder?
-
Shown while the camera is starting or stopped. Default
ScannerPlaceholder.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- strings → ScannerStrings?
-
The texts; default those of a ScannerScope around the scanner, or
English.
final
- tapToFocus → bool
-
Focus where the user taps.
final
- template → ScannerTemplate?
-
A ready-made screen around the camera; see ScannerTemplate.
final
- theme → ScannerTheme?
-
Colors and shapes, merged onto the template's theme, which is
merged onto the theme of a ScannerScope around the scanner.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< BarcodeScanner> -
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