findNetworkPrinter function

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

Implementation

Future<List<String>> findNetworkPrinter({int port: 9100}) async {
  final _info = NetworkInfo();
  String? ip = await (_info.getWifiIP());
  if (ip?.isEmpty == true) {
    ip = (await getAddresses()).first;
  }
  PosPrinterManager.logger.info("ip: $ip");
  final String subnet = ip!.substring(0, ip.lastIndexOf('.'));
  PosPrinterManager.logger.info("subnet: $subnet");

  final stream = NetworkAnalyzer.discover2(subnet, port);
  var results = await stream.toList();
  return [
    ...results.where((entry) => entry.exists).toList().map((e) => e.ip).toList()
  ];
}