save method Null safety

Uint8List save()

Save the template
The format is platform-independent.

Implementation

Uint8List save() {
  Pointer<Pointer<Uint8>> _emptyPointerList = malloc.allocate(sizeOf<Pointer<Pointer<Uint8>>>() * 2);
  _emptyPointerList[0] = malloc.allocate(sizeOf<Pointer<Int32>>());
  _emptyPointerList[1] = malloc.allocate(1000);

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

  final templateSave = _dll_handle.lookupFunction<_Template_save_c, _Template_save_dart>(_c_namespace + 'Template_save');

  var exception = _getException();
  templateSave(_impl, _emptyPointerList.cast(), Pointer.fromFunction(writeFunc), exception);
  checkException(exception, _dll_handle);

  Uint8List result = Uint8List(byteCount.value);
  for (var i = 0; i < byteCount.value; i++) {
    result[i] = _emptyPointerList[1][i];
  }
  malloc.free(_emptyPointerList[0]);
  malloc.free(_emptyPointerList[1]);
  malloc.free(_emptyPointerList);

  return result;
}