extractGS1Values method

List<GS1Description> extractGS1Values(
  1. String gs1,
  2. GS1Type type
)

Splits a gs1 code into its GS1Details. If type is GS1Type.unknown returns [].

Implementation

List<GS1Description> extractGS1Values(String gs1, GS1Type type) {
  if (type == GS1Type.unknown) return [];

  final onlyDigits = gs1.replaceAll(_everythingExceptDigits, '');
  final digits1to4 = onlyDigits.substring(0, 4);
  final rest = onlyDigits.substring(4);
  return [
    GS1Description(digits1to4, _GS1Values.digits1To4[digits1to4]),
    GS1Description(rest, _GS1Values.assetIdentifier),
  ];
}