generatePrintCmd static method

Future<List<List<int>>> generatePrintCmd({
  1. String? imgPath,
  2. Uint8List? imgData,
  3. required PrintTypeEnum printType,
  4. int imgSizeLimit = 550 * 1000,
})

生成打印圖片指令 singleByteSizeLimit: 单次写入的长度限制

Implementation

static Future<List<List<int>>> generatePrintCmd({
  String? imgPath,
  Uint8List? imgData,
  required PrintTypeEnum printType,
  int imgSizeLimit = 550 * 1000,
}) async {
  if (imgPath == null && imgData == null) {
    throw Exception(
        'generatePrintCmd error : imgPath and imgData cannot be empty at the same time');
  }
  Uint8List imgBytes;
  if (imgData != null) {
    imgBytes = imgData;
  } else {
    imgBytes = await ImageTool.getImage(imgPath!);
  }
  final cmdData = printType == PrintTypeEnum.receipt
      ? await ESCPrinterService(
    imgBytes,
    imgSizeLimit: imgSizeLimit,
  ).getBytes()
      : await TscPrinterService(
    imgBytes,
  ).getBytes();
  return cmdData;
}