Juliantje15
Juliantje15

Reputation: 138

When should Uint8 in Dart/Flutter be used?

I'm working on a flutter project with lots of bytes and byte arrays. I noticed that i had access to Uint8 and Uint8List. If i understand correctly, the Uint8List will save some memory over using a normal list with bytes. However, it seems that the Uint8List only accepts regular integers. Is there any usecase for using Uint8 type? Or should i be using the int type for bytes?

Upvotes: 7

Views: 1817

Answers (1)

Roel van Endhoven
Roel van Endhoven

Reputation: 180

Edit: The question is answered here

According to the documentation here, it accepts integers and then truncates those to the lower eight bits. This means you can effectively store four list entries in a standard 32 bit integer. When retrieving an integer, the integer is most likely prepended by the amount of bytes a reqular int uses.

Upvotes: 4

Related Questions