AmolGangadhare / flutter_barcode_scanner

Barcode scanner plugin for flutter. Supports barcode scanning for Android and iOS
https://pub.dev/packages/flutter_barcode_scanner
MIT License
379 stars 454 forks source link

UPC BARCODE confused with EAN BARCODE (iOS) #171

Open jjsebastianfuertes opened 3 years ago

jjsebastianfuertes commented 3 years ago

Describe the bug scanning UPC BARCODE on iOS device returns the number but with a zero at the beginning. It should return only the number without the zero.

To Reproduce Steps to reproduce the behavior:

  1. Open scanner
  2. Scan a product with a UPC BARCODE
  3. it returns 0884912129741 but it should return 884912129741

Expected behavior the code returned should be the one on the BARCODE without implementing a zero at the beginning. This behaivor only happens on iOS

SCREENSHOTS

barcode

Smartphone:

santiracca commented 3 years ago

@jjsebastianfuertes Have the same problem! any updates on this?

Is it safe to assume that ios always returns a leading zero?

santiracca commented 3 years ago

any updates on this? @AmolGangadhare

DanielCardona commented 2 years ago

Facing the same problem here. Thanks for any update on the issue ;-). Nice package.

callawey commented 2 years ago

this is not from the library but from ios. of course library should handle it. i corrected it myself.

apple explanation UPC-A is a formal subset of EAN-13. A decoded UPC-A barcode is output as AVMetadataObjectTypeEAN13Code with a leading zero in the stringValue.

you need to change below function inside

SwiftFlutterBarcodeScannerPlugin.swift -> BarcodeScannerViewController -> metadataOutput

 if metadataObj.stringValue != nil {
    if(SwiftFlutterBarcodeScannerPlugin.isContinuousScan){
        SwiftFlutterBarcodeScannerPlugin.onBarcodeScanReceiver(barcode: metadataObj.stringValue!)
    }else{
        launchApp(decodedURL: metadataObj.stringValue!)
    }
}

to this one

var code = metadataObj.stringValue
if code != nil {
    if metadataObj.type == AVMetadataObject.ObjectType.ean13 && code!.hasPrefix("0") {
        code = String(code!.dropFirst())
    }
    if(SwiftFlutterBarcodeScannerPlugin.isContinuousScan){
        SwiftFlutterBarcodeScannerPlugin.onBarcodeScanReceiver(barcode: code!)
    }else{
        launchApp(decodedURL: code!)
    }
}