discover static method

discover let you explore all bluetooth printer nearby your device On Android, this now uses scan for more comprehensive discovery.

Implementation

static Future<List<BluetoothPrinter>> discover() async {
  if (Platform.isAndroid) {
    // Use scan stream and collect for a short period?
    // Or just return bonded?
    // User asked for "scan", so likely they will use scan() directly.
    // But preserving discover() behavior:
    final bluetooth = DragoBluePrinter.instance;
    List<BluetoothDevice> devices = await bluetooth.getBondedDevices();
    return devices
        .map(
          (r) => BluetoothPrinter(
            name: r.name,
            address: r.address,
            type: r.type,
          ),
        )
        .toList();
  }
  var results = await flutterPrinterChannel.invokeMethod('getBluetoothList');
  return List.from(results)
      .map((r) => BluetoothPrinter(name: r['name'], address: r['address']))
      .toList();
}