search method Null safety

Future<List<List<SearchResult>>> search(
  1. List<Template> queries_templates,
  2. TemplateIndex templates_index,
  3. int k,
  4. {SearchAccelerationType acceleration = SearchAccelerationType.SEARCH_ACCELERATION_1}
)

Implementation

Future<List<List<SearchResult>>> search(List<Template> queries_templates, TemplateIndex templates_index, int k,
    {SearchAccelerationType acceleration = SearchAccelerationType.SEARCH_ACCELERATION_1}) async {
  ReceivePort receivePort = ReceivePort();
  List<List<SearchResult>> result = [];

  List<int> pointers = [];

  queries_templates.forEach((template) => pointers.add(template._impl.address));

  _sendPort.send({
    "event": _RecognizerEvents.SEARCH,
    "sendPort": receivePort.sendPort,
    "queries_templates": pointers,
    "templateIndex": templates_index._impl.address,
    "k": k,
    "acceleration": acceleration
  });

  List<List<Map<String, dynamic>>> data = await receivePort.first;

  for (List<Map<String, dynamic>> listMapData in data) {
    List<SearchResult> searchResults = [];

    for (Map<String, dynamic> mapData in listMapData) {
      searchResults.add(SearchResult(mapData["i"], MatchResult(mapData["distance"]!, mapData["fa_r"]!, mapData["fr_r"]!, mapData["score"]!)));
    }

    result.add(searchResults);
  }

  return result;
}