CameraScannerWidget class

A widget that displays a live camera preview and scans for credit card information.

This widget uses the device's camera to capture images and performs optical character recognition (OCR) to extract text from the images. It then analyzes the extracted text to identify credit card numbers, cardholder names, and expiry dates.

The widget provides callbacks for successful scans and errors, allowing developers to handle scanned credit card data and display appropriate UI feedback.

To use the widget, simply create an instance of CameraScannerWidget and provide the required callbacks:

CameraScannerWidget(
  onScan: (context, creditCardModel) {
    // Handle the scanned credit card data here
  },
  loadingHolder: Center(child: CircularProgressIndicator()),
  onNoCamera: () {
    // Handle the case where no camera is available
  },
)

The onScan callback is triggered when a credit card is successfully scanned, providing a CreditCardModel object containing the extracted card information.

The loadingHolder widget is displayed while the camera is initializing.

The onNoCamera callback is triggered if no camera is available on the device.

Inheritance

Constructors

CameraScannerWidget.new({Key? key, required void onScan(BuildContext, CreditCardModel?), required Widget loadingHolder, required void onNoCamera(), double? aspectRatio, bool cardNumber = true, bool cardHolder = true, bool cardExpiryDate = true, Color? colorOverlay, ShapeBorder? shapeBorder, bool useLuhnValidation = true, bool debug = kDebugMode, Duration? durationOfNextFrame, ResolutionPreset? resolutionPreset})
Creates a CameraScannerWidget.
const

Properties

aspectRatio double?
Aspect ratio for the camera preview. If null, uses the device's screen aspect ratio.
final
cardExpiryDate bool
Whether to scan for the card's expiry date. Defaults to true.
final
cardHolder bool
Whether to scan for the card holder's name. Defaults to true.
final
cardNumber bool
Whether to scan for the card number. Defaults to true.
final
colorOverlay Color?
The color of the overlay that highlights the credit card scanning area.
final
debug bool
final
durationOfNextFrame Duration?
the duration of the next frame
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
loadingHolder Widget
Widget to display while the camera is initializing.
final
onNoCamera → void Function()
Callback function called when no camera is available on the device.
final
onScan → void Function(BuildContext, CreditCardModel?)
Callback function called when a credit card is successfully scanned.
final
resolutionPreset → ResolutionPreset?
The resolution preset for the camera. Defaults to ResolutionPreset.high.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shapeBorder ShapeBorder?
The shape of the border surrounding the credit card scanning area.
final
useLuhnValidation bool
this will force validation of the card number means it will apply luhn algorithm to the card number
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<CameraScannerWidget>
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