onPrinterDiscovered method
void
onPrinterDiscovered()
override
Registers a callback function to listen for discovered printers during the discovery process.
callback
: A function that is called when a printer is discovered. The function receives the following parameters:identifier
: The unique identifier of the discovered printer.interfaceType
: The connection interface type (e.g., USB, Bluetooth).model
: The model name of the discovered printer.
Streams printer discovery events via eventChannel.
Implementation
@override
void onPrinterDiscovered(
Function(String identifier, String interfaceType, String model)
callback) {
eventChannel.receiveBroadcastStream().listen((event) {
final Map<String, dynamic> data = Map<String, dynamic>.from(event);
final String identifier = data['identifier'];
final String interfaceType = data["interfaceType"];
final String model = data["model"];
debugPrint(
"Printer Discovered: Identifier - $identifier, Interface - $interfaceType, model - $model");
callback(identifier, interfaceType, model);
}, onError: (error) {
debugPrint('Error receiving printer discovery event: $error');
});
}