onPrinterDiscovered method

  1. @override
void onPrinterDiscovered(
  1. dynamic callback(
    1. String identifier,
    2. String interfaceType,
    3. String model
    )
)
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');
  });
}