mohesu / barcode_scanner

A universal barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS.
Apache License 2.0
30 stars 23 forks source link

onscan #112

Open firelove68 opened 3 weeks ago

firelove68 commented 3 weeks ago

hi why onscan method isn't more avaliable? i have this error: "The named parameter 'onScan' isn't defined."

onScan: (String value) { debugPrint(value); setState(() { _qrCodeResult = value; }); }, so how i can resolve it?

[√] Flutter (Channel stable, 3.22.1, on Microsoft Windows [Versione 10.0.22631.3672], locale it-IT) [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [√] Chrome - develop for the web [√] Visual Studio - develop Windows apps (Visual Studio Enterprise 2022 17.10.1) [√] Android Studio (version 2023.3) [√] VS Code (version 1.72.2) [√] Connected device (4 available) [√] Network resources Thanks

rvndsngwn commented 1 week ago

Hi @firelove68, onScan method has been removed, kindly use onDetect method.

firelove68 commented 1 week ago

ok but in official documentation still there!

rvndsngwn commented 1 week ago

Okay, I'll look into. Thanks.

mfauzann commented 4 days ago

ly use onDetect method

hi @rvndsngwn can you give some example to use ? I'm looking for the latest documentation, but nothing. thank you.

rvndsngwn commented 3 days ago

Hi @mfauzann & @firelove68

The onScan method has been removed or renamed in mobile_scanner: ^5.1.1 to improve its functionality. The onDetect function provides the BarcodeCapture object, which has multiple values.

You can use these values based on your requirements. For example if you want scan only barcode/qrcode with noDuplicates you can use like this:

Row string value example:

onDetect: (BarcodeCapture capture)   {
  final String? scannedValue = capture.barcodes.first.rawValue;
},

Other examples:

onDetect: (BarcodeCapture capture)   {
  /// The `Uint8List` image is only available if `returnImage` is set to `true`.
  final Uint8List? image = capture.image;

  /// row data of the barcode
  final Object? raw = capture.raw;

  /// List of scanned barcodes if any
  final List<Barcode> barcodes = capture.barcodes;
},

BarcodeCapture:-

  /// The list of scanned barcodes.
  final List<Barcode> barcodes;

  /// The bytes of the image that is embedded in the barcode.
  ///
  /// This null if [MobileScannerController.returnImage] is false,
  /// or if there is no available image.
  final Uint8List? image;

  /// The raw data of the scanned barcode.
  final Object? raw;

  /// The size of the scanned barcode.
  final Size size;

Barcode:-

  /// The calendar event that is embedded in the barcode.
  final CalendarEvent? calendarEvent;

  /// The contact information that is embedded in the barcode.
  final ContactInfo? contactInfo;

  /// The four corner points of the barcode,
  /// in clockwise order, starting with the top-left point.
  ///
  /// Due to the possible perspective distortions, this is not necessarily a rectangle.
  ///
  /// This list is empty if the corners can not be determined.
  final List<Offset> corners;

  /// The barcode value in a user-friendly format.
  ///
  /// This value may omit some of the information encoded in the barcode.
  /// For example, if [rawValue] returns `MEBKM:TITLE:Google;URL://www.google.com;;`,
  /// the display value might be `//www.google.com`.
  ///
  /// This value may be multiline if line breaks are encoded in the barcode.
  /// This value may include the supplement value.
  ///
  /// This is null if there is no user-friendly value for the given barcode.
  final String? displayValue;

  /// The driver license information that is embedded in the barcode.
  final DriverLicense? driverLicense;

  /// The email message that is embedded in the barcode.
  final Email? email;

  /// The format of the barcode.
  final BarcodeFormat format;

  /// The geographic point that is embedded in the barcode.
  final GeoPoint? geoPoint;

  /// The phone number that is embedded in the barcode.
  final Phone? phone;

  /// The raw bytes of the barcode.
  ///
  /// This is null if the raw bytes are not available.
  final Uint8List? rawBytes;

  /// The raw value of `UTF-8` encoded barcodes.
  ///
  /// Structured values are not parsed,
  /// for example: 'MEBKM:TITLE:Google;URL://www.google.com;;'.
  ///
  /// For non-UTF-8 barcodes, prefer using [rawBytes] instead.
  ///
  /// This is null if the raw value is not available.
  final String? rawValue;

  /// The SMS message that is embedded in the barcode.
  final SMS? sms;

  /// The contextual type of the [format] of the barcode.
  ///
  /// For example: TYPE_TEXT, TYPE_PRODUCT, TYPE_URL, etc.
  ///
  /// For types that are recognized,
  /// but could not be parsed correctly, [BarcodeType.text] will be returned.
  ///
  /// For types that are not recognised, [BarcodeType.unknown] will be returned.
  ///
  /// If a given barcode was not correctly identified,
  /// consider parsing [rawValue] manually instead.
  final BarcodeType type;

  /// The URL bookmark that is embedded in the barcode.
  final UrlBookmark? url;

  /// The Wireless network information that is embedded in the barcode.
  final WiFi? wifi;
mfauzann commented 3 days ago

Thank you for the Thank you for your help, explanation and examples