parse method

  1. @override
ProductParsedResult? parse(
  1. Result result
)
override

Attempts to parse the raw Result's contents as a particular type of information (email, URL, etc.) and return a ParsedResult encapsulating the result of parsing.

@param theResult the raw Result to parse @return ParsedResult encapsulating the parsing result

Implementation

@override
ProductParsedResult? parse(Result result) {
  final format = result.barcodeFormat;
  if (!(format == BarcodeFormat.upcA ||
      format == BarcodeFormat.upcE ||
      format == BarcodeFormat.ean8 ||
      format == BarcodeFormat.ean13)) {
    return null;
  }
  final rawText = ResultParser.getMassagedText(result);
  if (!isStringOfDigits(rawText, rawText.length)) {
    return null;
  }
  // Not actually checking the checksum again here

  String normalizedProductID;
  // Expand UPC-E for purposes of searching
  if (format == BarcodeFormat.upcE && rawText.length == 8) {
    normalizedProductID = UPCEReader.convertUPCEtoUPCA(rawText);
  } else {
    normalizedProductID = rawText;
  }

  return ProductParsedResult(rawText, normalizedProductID);
}