parse method
Parse barcode string
Implementation
GS1Barcode parse(String data, {CodeType? codeType}) {
if (data.isEmpty) {
GS1DataException(message: 'Barcode is empty');
}
final codeWithRest = _codeParser(
_normalize(data, codeType: codeType),
);
if (codeWithRest.code.type == CodeType.UNDEFINED &&
!_config.allowEmptyPrefix) {
throw GS1DataException(message: 'FNC1 prefix not found');
}
String restOfBarcode = codeWithRest.rest;
if (restOfBarcode.isEmpty) {
throw GS1DataException(message: 'No date present');
}
final elements = <String, GS1ParsedElement>{};
while (restOfBarcode.isNotEmpty) {
final res = _identifyAI(restOfBarcode);
elements.putIfAbsent(res.element.aiCode, () => res.element);
restOfBarcode = res.rest;
}
return GS1Barcode(
code: codeWithRest.code,
elements: elements,
);
}