flutterdart-pubdartuint8list

Dart - Whats equivalent of C# Stream/MemoryStream and stream.WriteByte(..) for Dart


Need to achieve following in dart

MemoryStream stream = new MemoryStream(288);
stream.WriteByte((byte) 13);
stream.WriteByte((byte) 12);
stream.WriteByte((byte) 10);
stream.WriteByte((byte) 8);
stream.WriteByte((byte) 6);
stream.WriteByte((byte) 9);
var result = stream.ToArray();

I am coming from C#/java background and trying to use Uint8List which is equivalent to byte[] and also more efficient than List<int>. While I can add int8 in Uint8List but Uint8List can only be initialized with fixed-length. I need something dynamic where I can just say write or add without the need of any index to add. No idea how add() of Uint8List works. Couldn't find much on the internet or in docs.


Solution

  • I don't believe that there is a standard equivalent. (There's a GitHub comment explaining why Uint8List requires a fixed length.)

    You instead could: