encode method

  1. @override
BitMatrix encode(
  1. String contents,
  2. BarcodeFormat format,
  3. int width,
  4. int height, [
  5. Map<EncodeHintType, Object>? hints,
])
override

@param contents The contents to encode in the barcode @param format The barcode format to generate @param width The preferred width in pixels @param height The preferred height in pixels @param hints Additional parameters to supply to the encoder @return BitMatrix representing encoded barcode image @throws WriterException if contents cannot be encoded legally in a format

Implementation

@override
BitMatrix encode(
  String contents,
  BarcodeFormat format,
  int width,
  int height, [
  Map<EncodeHintType, Object>? hints,
]) {
  Writer writer;
  switch (format) {
    case BarcodeFormat.EAN_8:
      writer = EAN8Writer();
      break;
    case BarcodeFormat.UPC_E:
      writer = UPCEWriter();
      break;
    case BarcodeFormat.EAN_13:
      writer = EAN13Writer();
      break;
    case BarcodeFormat.UPC_A:
      writer = UPCAWriter();
      break;
    case BarcodeFormat.QR_CODE:
      writer = QRCodeWriter();
      break;
    case BarcodeFormat.CODE_39:
      writer = Code39Writer();
      break;
    case BarcodeFormat.CODE_93:
      writer = Code93Writer();
      break;
    case BarcodeFormat.CODE_128:
      writer = Code128Writer();
      break;
    case BarcodeFormat.ITF:
      writer = ITFWriter();
      break;
    case BarcodeFormat.PDF_417:
      writer = PDF417Writer();
      break;
    case BarcodeFormat.CODABAR:
      writer = CodaBarWriter();
      break;
    case BarcodeFormat.DATA_MATRIX:
      writer = DataMatrixWriter();
      break;
    case BarcodeFormat.AZTEC:
      writer = AztecWriter();
      break;
    default:
      throw ArgumentError('No encoder available for format $format');
  }
  return writer.encode(contents, format, width, height, hints);
}