discoverPrinters static method

DiscoverResult<UsbPrinterInfo> discoverPrinters()

Implementation

static DiscoverResult<UsbPrinterInfo> discoverPrinters() async {
  if (Platform.isAndroid) {
    final List<dynamic> results = await flutterPrinterChannel.invokeMethod('getList');
    return results
        .map((dynamic r) => PrinterDiscovered<UsbPrinterInfo>(
              name: r['product'],
              detail: UsbPrinterInfo.Android(
                vendorId: r['vendorId'],
                productId: r['productId'],
                manufacturer: r['manufacturer'],
                product: r['product'],
                name: r['name'],
                deviceId: r['deviceId'],
              ),
            ))
        .toList();
  }
  if (Platform.isWindows) {
    final List<dynamic> results = await flutterPrinterChannel.invokeMethod('getList');
    return results
        .map((dynamic result) => PrinterDiscovered<UsbPrinterInfo>(
              name: result['name'],
              detail: UsbPrinterInfo.Windows(isDefault: result['default'], name: result['name'], model: result['model']),
            ))
        .toList();
  }
  return [];
}