searchMdnsDevices static method Null safety

Future<List<ActiveHost>> searchMdnsDevices(
  1. {bool forceUseOfSavedSrvRecordList = false}
)

This method searching for all the mdns devices in the network. TODO: The implementation is Lacking! and will not find all the TODO: results that actual exist in the network!, only some of them. TODO: This is because missing functionality in dart TODO: https://github.com/flutter/flutter/issues/97210 TODO: In some cases we resolve this missing functionality using TODO: specific os tools.

Implementation

static Future<List<ActiveHost>> searchMdnsDevices({
  bool forceUseOfSavedSrvRecordList = false,
}) async {
  List<String> srvRecordListToSearchIn;

  if (forceUseOfSavedSrvRecordList) {
    srvRecordListToSearchIn = tcpSrvRecordsList;
    srvRecordListToSearchIn.addAll(udpSrvRecordsList);
  } else {
    final List<String>? srvRecordsFromOs = await SrvList.getSrvRecordList();

    if (srvRecordsFromOs == null || srvRecordsFromOs.isEmpty) {
      srvRecordListToSearchIn = tcpSrvRecordsList;
      srvRecordListToSearchIn.addAll(udpSrvRecordsList);
    } else {
      srvRecordListToSearchIn = srvRecordsFromOs;
    }
  }

  final List<Future<List<ActiveHost>>> activeHostListsFuture = [];
  for (final String srvRecord in srvRecordListToSearchIn) {
    activeHostListsFuture.add(_findingMdnsWithAddress(srvRecord));
  }

  final List<ActiveHost> activeHostList = [];

  for (final Future<List<ActiveHost>> activeHostListFuture
      in activeHostListsFuture) {
    activeHostList.addAll(await activeHostListFuture);
  }

  return activeHostList;
}