I m与另一个能够打印产品标签的兄弟一道开发一个仪器。 所需标识尺寸为62毫米×29毫米。 经过一些研究,我认为这个问题与印刷商Info的“labelNameIndex”有关。 当我把NameIndex贴上17个标签时,该标签是用的,但并没有将标签长度固定在29毫米。 时间长短取决于内容。 我还发现,当“NameIndex”被定为8个,相当于62毫米×29毫米的面积时,它回去了以下错误:
{labelType:-1, maxOfBatteryResidual Quantity: -1, 标签Id:-1, ACConnected:{id:-1, 姓名:不明}, 电池Residual Quantity 级别:-1, isBatteryMounted:{id:-1, name:ident}, celllevel: -1, 错误Code:{名称: ERROR_WRONG_LABEL, id: -1, >
void printResult(
BuildContext context, {
required PrintModel model,
}) async {
if (selectedPrinter.value == null) {
ToastUtils.show(StringStyles.printerNotReady.tr);
}
EasyLoading.show(status: StringStyles.printing.tr);
var printer = Printer();
var printInfo = PrinterInfo();
printInfo.printerModel = Model.QL_810W;
printInfo.printMode = PrintMode.FIT_TO_PAGE;
printInfo.isAutoCut = false;
printInfo.port = Port.NET;
printInfo.paperSize = PaperSize.CUSTOM;
// printInfo.customPaperLength = 29;
// printInfo.customPaperWidth = 62;
printInfo.printQuality = PrintQuality.HIGH_RESOLUTION;
printInfo.labelNameIndex = 8;
// Set the printer info so we can use the SDK to get the printers.
await printer.setPrinterInfo(printInfo);
// Get a list of printers with my model available in the network.
List<NetPrinter> printers =
await printer.getNetPrinters([Model.QL_810W.getName()]);
if (printers.indexWhere((element) =>
element.macAddress == selectedPrinter.value?.macAddress) ==
-1) {
EasyLoading.dismiss();
ToastUtils.show(StringStyles.printerDisconnected.tr);
getMyNetworkPrinters();
return;
}
// Get the IP Address from the first printer found.
printInfo.ipAddress = printers.single.ipAddress;
printer.setPrinterInfo(printInfo);
var totalNum = 0;
for (var element in model.products) {
var num = int.parse(element.num);
totalNum += num;
}
var index = 1;
for (var element in model.products) {
var num = int.parse(element.num);
for (int i = 0; i < num; i++) {
final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder(
ui.ParagraphStyle(
textAlign: TextAlign.left,
fontSize: 20,
textDirection: TextDirection.ltr,
),
)
..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 16))
..addText( James ${model.phoneNumber}
)
..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 16))
..addText( App Order
)
..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 20))
..addText( To-Go #${model.orderNumber} ($index of $totalNum)
)
..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 20))
..addText( ${element.title}
)
..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 16))
..addText(element.tag);
final ui.Paragraph paragraph = paragraphBuilder.build()
..layout(ui.ParagraphConstraints(
width: MediaQuery.of(context).size.width - 8));
await printer.printText(paragraph);
index++;
}
}
EasyLoading.dismiss();
}
Here, I show the labelNameIndex and the corresponding size.
class QL700 implements ALabelName {
final int _id;
final String _name;
static const String _model = "QL700";
const QL700._internal(this._id, this._name);
static const W17H54 = const QL700._internal(1, "W17H54");
static const W17H87 = const QL700._internal(2, "W17H87");
static const W23H23 = const QL700._internal(3, "W23H23");
static const W29H42 = const QL700._internal(4, "W29H42");
static const W29H90 = const QL700._internal(5, "W29H90");
static const W38H90 = const QL700._internal(6, "W38H90");
static const W39H48 = const QL700._internal(7, "W39H48");
static const W52H29 = const QL700._internal(8, "W52H29");
static const W62H29 = const QL700._internal(9, "W62H29");
static const W62H100 = const QL700._internal(10, "W62H100");
static const W12 = const QL700._internal(11, "W12");
static const W29 = const QL700._internal(12, "W29");
static const W38 = const QL700._internal(13, "W38");
static const W50 = const QL700._internal(14, "W50");
static const W54 = const QL700._internal(15, "W54");
static const W62 = const QL700._internal(16, "W62");
static const W60H86 = const QL700._internal(17, "W60H86");
static const W62RB = const QL700._internal(38, "W62RB");
static const W54H29 = const QL700._internal(39, "W54H29");
static const UNSUPPORT = const QL700._internal(255, "UNSUPPORT");
static final _values = [
W17H54,
W17H87,
W23H23,
W29H42,
W29H90,
W38H90,
W39H48,
W52H29,
W62H29,
W62H100,
W12,
W29,
W38,
W50,
W54,
W62,
W60H86,
W62RB,
W54H29,
UNSUPPORT,
];
int getId() {
return _id;
}
@override
String getName() {
return _name;
}
static int getItemId(index) {
if (index < 0 || index > _values.length) {
return UNSUPPORT.getId();
}
return _values[index].getId();
}
static QL700 valueFromID(int id) {
for (int i = 0; i < _values.length; ++i) {
QL700 num = _values[i];
if (num.getId() == id) {
return num;
}
}
return UNSUPPORT;
}
static List<QL700> getValues() => List.from(_values);
static int ordinalFromID(int id) {
for (int i = 0; i < _values.length; ++i) {
QL700 num = _values[i];
if (num.getId() == id) {
return i;
}
}
return -1;
}
static QL700 fromMap(Map<dynamic, dynamic> map) {
int id = map["id"];
return QL700.valueFromID(id);
}
static QL700 fromIndex (int index) {
if (index < 0 ||index >= _values.length ) {
return UNSUPPORT;
}
return _values[index];
}
Map<String, dynamic> toMap() {
return {"id": _id,
"name": _name,
"model": _model
};
}
}