createDynamicTemplateIndexWithTemplates method Null safety

DynamicTemplateIndex createDynamicTemplateIndexWithTemplates(
  1. List<ContextTemplate> templates,
  2. List<String> uuids,
  3. Map config
)

Implementation

DynamicTemplateIndex createDynamicTemplateIndexWithTemplates(List<ContextTemplate> templates, List<String> uuids, Map config) {
  if (templates.length != uuids.length) {
    throw Exception("templates.length != uuids.length");
  }

  final exception = _getException();

  Context meta_ctx = this.createContext(config);

  final constructor =
  _dll_handle.lookupFunction<_createDynamicTemplateIndex_1_c, _createDynamicTemplateIndex_1_dart>(
      "${_c_namespace}FacerecService_createDynamicTemplateIndex_1");
  Pointer<Pointer<Void>> templatesImpls = malloc.allocate(sizeOf<Pointer<Void>>() * uuids.length);
  Pointer<Pointer<Utf8>> uuidsPointers = malloc.allocate(sizeOf<Pointer<Utf8>>() * uuids.length);

  for (int i = 0; i < templates.length; i++) {
    templatesImpls[i] = templates[i]._impl;
    uuidsPointers[i] = uuids[i].toNativeUtf8();
  }

  DynamicTemplateIndex result = DynamicTemplateIndex(
      _dll_handle, constructor(_impl, templatesImpls, uuidsPointers, templates.length, meta_ctx._impl, exception));

  malloc.free(templatesImpls);
  malloc.free(uuidsPointers);

  checkException(exception, _dll_handle);

  return result;
}