copyUint8ListFromOwnedFfiPtr function
From an owned pointer allocated in native code, copy the data into the Dart
VM Heap as a Uint8List and then immediately free
the owned ffi pointer.
Implementation
Uint8List? copyUint8ListFromOwnedFfiPtr(Pointer<Uint8> data, int length) {
if (data == nullptr || length == 0) {
return null;
}
final Uint8List out = Uint8List.fromList(data.asTypedList(length));
malloc.free(data);
return out;
}