formatGS1 method

String formatGS1(
  1. String gs1, {
  2. GS1Type type = GS1Type.unknown,
})

Formats gs1 to match the common format of type (defaults to GS1Type.unknown (does not get recognized)).

Implementation

String formatGS1(
  String gs1, {
  GS1Type type = GS1Type.unknown,
}) {
  final onlyDigits = gs1.replaceAll(_everythingExceptDigits, '');

  switch (type) {
    case GS1Type.giai:
      return '(' + onlyDigits.substring(0, 4) + ')' + onlyDigits.substring(4);
    case GS1Type.unknown:
      return onlyDigits;
  }
}