I have a buffer byteBuffer in ByteData format that is 500 bytes long. It’s a list of 250 Uint16 values. I can convert it to List using a loop with the following code (and it works).
List<int> data = [];
// Convert ByteData to List<int>
for (var i = 0; i < 500; i += 2) {
data.add(byteBuffer.getUint16(i, Endian.little));
}
If I wanted to convert the List of int into a List of double, I can use a map function as follows:
var doubleData = data.map((i) => i.toDouble()).toList();
I’m wondering if there is a way to create a map function to go from the ByteData to List without using the loop?
I’ve tried doing stuff like:
List<int> data = byteBuffer.map((i) => i.getUint16(i, Endian.little)).toList();
But map is not defined for ByteData. Is there a way to map it or do something similar, other than using a loop?