I'm developing an app with another_brother that can print product labels. The required label size is 62mm x 29mm. After some research, I believe the issue relates to the "labelNameIndex" in PrinterInfo. When I set the labelNameIndex to 17, it works, but doesn't fix the label length to 29mm. The length depends on the content. I also found that when labelNameIndex is set to 8, which should correspond to a size of 62mm x 29mm, it returns the following error:
{labelType: -1, maxOfBatteryResidualQuantityLevel: -1, labelId: -1, isACConnected: {id: -1, name: Unknown}, batteryResidualQuantityLevel: -1, isBatteryMounted: {id: -1, name: Unknown}, batteryLevel: -1, errorCode: {name: 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}\n')
..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 16))
..addText('App Order\n')
..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 20))
..addText('To-Go #${model.orderNumber} ($index of $totalNum)\n')
..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 20))
..addText('${element.title}\n')
..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
};
}
}
After conducting research and various tests, I've discovered that the "labelNameIndex" setting depends on the specific type of label being used. Previously, I incorrectly set the "labelNameIndex" to 8 when using a 62mmx5m label, which was not the right configuration. The correct "labelNameIndex" for this label is actually 17.
Currently, I am using a 62mmx29mm label, which requires the "labelNameIndex" to be set at 8. With this adjustment, everything is working perfectly. Therefore, I believe there are no issues; it's just a matter of using the correct "labelNameIndex" for the specific label you are working with.