Barcode.upcE constructor

Barcode.upcE(
  1. List barcodeData
)

UPC-E

k = 6 – 8, 11, 12 d = '0' – '9' (However, d0 = '0' when k = 7, 8, 11, 12)

Implementation

Barcode.upcE(List<dynamic> barcodeData) {
  final k = barcodeData.length;
  if (![6, 7, 8, 11, 12].contains(k)) {
    throw Exception('Barcode: Wrong data range');
  }

  if ([7, 8, 11, 12].contains(k) && barcodeData[0].toString() != '0') {
    throw Exception('Barcode: Data is not valid');
  }

  final numeric = RegExp(r'^[0-9]$');
  final bool isDataValid =
      barcodeData.every((dynamic d) => numeric.hasMatch(d.toString()));
  if (!isDataValid) {
    throw Exception('Barcode: Data is not valid');
  }

  _type = BarcodeType.upcE;
  _data = _convertData(barcodeData);
}