parseGS1 method

BarcodeData? parseGS1(
  1. String barcode
)

Implementation

BarcodeData? parseGS1(String barcode) {
  try {
    GS1Barcode gs1barcode = parseBarcode(barcode);

    if (gs1barcode.code.type == CodeType.GS1_128) {
      final String? ssccCode = _barcodeUtils.getSSCCCode(gs1barcode);
      final String? itemCode = _barcodeUtils.getUnitItemCode(gs1barcode);

      if (ssccCode != null || itemCode != null) {
        final BarcodeData barcodeData = BarcodeData(
          barcodeId: ssccCode != null ? BarcodeId.huSSCC : BarcodeId.huItem,
          code: ssccCode ?? itemCode!,
          gs1barcode: gs1barcode,
        );

        return barcodeData;
      }
    } else if (gs1barcode.code.type == CodeType.UNDEFINED) {
      if (_barcodeUtils.barcodesDictionary.isSSCC(barcode)) {
        return BarcodeData(
          barcodeId: BarcodeId.huSSCC,
          code: barcode,
          gs1barcode: gs1barcode,
        );
      }
    }
    return null;
  } catch (_) {
    return null;
  }
}