loadTemplate method Null safety

Template loadTemplate(
  1. Uint8List binary_stream
)

Load the template.
The format is platform-independent.
Only the templates that were created with the same method
(i.e. with the same ini_file) can be loaded.
binary_stream - Input stream object. The file stream (std::ifstream) must be opened with the std::ios_base::binary flag.
return - Loaded template.

Implementation

Template loadTemplate(Uint8List binary_stream) {
  var exception = _getException();
  final loadTemplate = _dll_handle.lookupFunction<_Recognizer_load_template_c, _Recognizer_load_template_dart>(_c_namespace + 'Recognizer_loadTemplate');

  Pointer<Pointer<Uint8>> _templatePointerStructure = malloc.allocate(sizeOf<Pointer<Pointer<Uint8>>>() * 2);
  _templatePointerStructure[0] = malloc.allocate(sizeOf<Pointer<Int32>>());
  _templatePointerStructure[1] = malloc.allocate(binary_stream.length);

  Pointer<Int32> byteCount = Pointer.fromAddress(_templatePointerStructure[0].address);
  byteCount.value = 0;

  for (var i = 0; i < binary_stream.length; i++) {
    _templatePointerStructure[1][i] = binary_stream[i];
  }

  final templPointer = loadTemplate(_impl, _templatePointerStructure.cast(), Pointer.fromFunction(readFunc), exception);
  checkException(exception, _dll_handle);

  malloc.free(_templatePointerStructure[0]);
  malloc.free(_templatePointerStructure[1]);
  malloc.free(_templatePointerStructure);
  // byteCount not free

  return Template(_dll_handle, templPointer);
}