findNetworkPrinter function

Future<List<String>> findNetworkPrinter({
  1. int port = 9100,
})

Implementation

Future<List<String>> findNetworkPrinter({int port = 9100}) async {
  String? currentIpAddress = await getDeviceIpAddress();
  if (currentIpAddress != null) {
    final stream = NetworkAnalyzer.discover2(
      currentIpAddress.substring(0, currentIpAddress.lastIndexOf('.')),
      port,
      timeout: const Duration(milliseconds: 5000),
    );
    var results = await stream.toList();
    return [
      ...results
          .where((entry) => entry.exists)
          .toList()
          .map((e) => e.ip)
          .toList()
    ];
  } else {
    return [];
  }
}