brother_print_library 0.1.7
brother_print_library: ^0.1.7 copied to clipboard
Flutter Android plugin wrapping BrotherPrintLibrary.aar for Brother mobile printer discovery, connection, status, and print commands.
brother_print_library #
Flutter Android plugin for wrapping BrotherPrintLibrary.aar.
The package exposes a Dart API over Brother printer discovery, channel opening, image/PDF/PRN/raw-data printing, print cancellation, and printer status queries. It is Android-only because the bundled SDK is an Android AAR.
Installation #
dependencies:
brother_print_library: ^0.1.4
Android apps must request runtime permissions required by the transport they use.
The plugin manifest declares common network, Bluetooth, BLE, and USB features,
but Android 6+ and Android 12+ still require the host app to request runtime
permissions such as location, BLUETOOTH_SCAN, and BLUETOOTH_CONNECT.
Usage #
final brother = BrotherPrintLibrary();
final search = await brother.searchNetwork(durationSeconds: 5);
final channel = search.channels.first;
final open = await brother.openChannel(channel);
if (!open.success) {
throw StateError(open.error?.code ?? 'Open channel failed');
}
final settings = BrotherPrintSettings(
printerModel: PrinterModel.QL_820NWB,
settingsType: 'QL',
options: <String, Object?>{
'labelSize': 'RollW62',
'numCopies': 1,
'autoCut': true,
'scaleMode': 'FitPaperAspect',
},
);
final result = await brother.printImage('/storage/emulated/0/Download/label.png', settings);
if (!result.success) {
throw StateError(result.error?.description ?? result.error?.code ?? 'Print failed');
}
await brother.closeChannel();
Print encoded image bytes through the Android Bitmap overload:
final imageBytes = await labelTemplate.imageBytes;
final result = await brother.printImageBytes(imageBytes, settings);
if (!result.success) {
throw StateError(result.error?.description ?? result.error?.code ?? 'Print failed');
}
Read typed printer status:
final statusResult = await brother.getPrinterStatus();
final status = statusResult.status;
if (statusResult.success && status != null) {
final model = status.model;
final errorCode = status.errorCode;
final labelSize = status.mediaInfo?.qlLabelSize;
final batteryLevel = status.batteryStatus?.chargeLevel?.current;
}
You can also open a known printer directly:
await brother.openChannel(BrotherChannel.wifi('192.168.1.100'));
await brother.openChannel(BrotherChannel.bluetooth('00:11:22:33:44:55'));
await brother.openChannel(BrotherChannel.bluetoothLowEnergy('local-name-or-address'));
await brother.openChannel(BrotherChannel.usb());
Print Settings #
BrotherPrintSettings.printerModel uses the typed PrinterModel enum. The
enum names match Brother SDK PrinterModel names, for example
PrinterModel.QL_820NWB.
BrotherPrintSettings forwards options to the Android SDK. Option enum values
must match Brother SDK names exactly. Common image fields include:
scaleMode, scaleValue, orientation, rotation, halftone, hAlignment,
vAlignment, compress, halftoneThreshold, numCopies, skipStatusCheck,
printQuality, and trimTrailingBlankData.
If workPath is not provided, Android uses an internal app cache directory.
You can still override it with options: {'workPath': '/path/to/work/dir'}.
Series-specific fields currently supported:
QL: labelSize, autoCut, cutAtEnd, resolution,
autoCutForEachPageCount, biColorRedEnhancement,
biColorGreenEnhancement, biColorBlueEnhancement,
feedDirectionMargins, workPath.
PT: labelSize, cutmarkPrint, cutPause, autoCut, halfCut,
chainPrint, specialTapePrint, resolution, autoCutForEachPageCount,
forceVanishingMargin, feedDirectionMargins, workPath.
PJ: paperSize, paperType, paperInsertionPosition, feedMode,
extraFeedDots, density, rollCase, printSpeed,
usingCarbonCopyPaper, printDashLine, workPath,
forceStretchPrintableArea.
TD: density, peelLabel, workPath, autoCut, cutAtEnd,
autoCutForEachPageCount, feedDirectionMargins, customRecord.
RJ: density, rotate180degrees, peelLabel,
feedDirectionMargins, workPath.
MW: paperSize, workPath.
Printer Status #
getPrinterStatus() returns BrotherStatusResult. Its status property is a
BrotherPrinterStatus? with fields matching Brother SDK PrinterStatus:
rawData, model, errorCode, mediaInfo, and batteryStatus.
mediaInfo is parsed as BrotherPrinterMediaInfo; batteryStatus is parsed as
BrotherPrinterBatteryStatus.
Bundled SDK #
This package includes android/libs/BrotherPrintLibrary.aar. Before publishing
or distributing this package, confirm that your Brother SDK license permits
redistribution through pub.flutter-io.cn or your private package registry.