discoverPrinters function

Future<List<PrinterDiscovered>> discoverPrinters({
  1. List<DiscoverResult Function()> modes = const <DiscoverResult<dynamic> Function()>[UsbPrinterConnector.discoverPrinters, TcpPrinterConnector.discoverPrinters],
})

Runs every function in modes and returns all the printers they found.

The default modes cover both transports: attached Android USB printers and network printers on the local private /24 networks. Network discovery takes a few seconds, so pass only the mode you need when that matters.

Implementation

Future<List<PrinterDiscovered<dynamic>>> discoverPrinters({
  List<DiscoverResult<dynamic> Function()> modes =
      const <DiscoverResult<dynamic> Function()>[
        UsbPrinterConnector.discoverPrinters,
        TcpPrinterConnector.discoverPrinters,
      ],
}) async {
  final List<PrinterDiscovered<dynamic>> result =
      <PrinterDiscovered<dynamic>>[];
  await Future.wait(
    modes.map((DiscoverResult<dynamic> Function() mode) async {
      result.addAll(await mode());
    }),
  );
  return result;
}