Dart/Flutter – How to convert String to Uint8List and vice versa

1. Convert String to Uint8List

Uint8List convertStringToUint8List(String str) {
  final List<int> codeUnits = str.codeUnits;
  final Uint8List unit8List = Uint8List.fromList(codeUnits);

  return unit8List;
}

2. Convert Uint8List to String

String convertUint8ListToString(Uint8List uint8list) {
  return String.fromCharCodes(uint8list);
}

Tagged : / / /
Subscribe
Notify of
guest

1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
swap
2 years ago

gandu

1
0
Would love your thoughts, please comment.x
()
x