Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onscan #112

Open
firelove68 opened this issue Jun 4, 2024 · 6 comments
Open

onscan #112

firelove68 opened this issue Jun 4, 2024 · 6 comments

Comments

@firelove68
Copy link

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
Copy link
Member

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

@firelove68
Copy link
Author

ok but in official documentation still there!

@rvndsngwn
Copy link
Member

Okay, I'll look into. Thanks.

@mfauzann
Copy link

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
Copy link
Member

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants