extract method

  1. @override
GS1Details? extract(
  1. String? input
)
override

Extracts an gs1 code from input and splits it up into its GS1Details Returns null if input is null or if the resulting gs1 code is invalid.

Implementation

@override
GS1Details? extract(String? input) {
  if (input == null) return null;
  final gs1 = input.replaceAll(_everythingExceptDigits, '');
  final type = _gs1DetailsService.determineType(gs1);

  if (!_gs1ValidatorService.validate(gs1, type)) return null;

  final List<GS1Description> values = _gs1DetailsService.extractGS1Values(gs1, type);

  return GS1Details(
    gs1Code: _gs1DetailsService.formatGS1(
      gs1,
      type: type,
    ),
    rawValue: input,
    gs1type: type,
    descriptions: values,
  );
}