toDartString method

String toDartString({
  1. int? length,

Converts this UTF-8 encoded string to a Dart string.

Decodes the UTF-8 code units of this zero-terminated byte array as Unicode code points and creates a Dart string containing those code points.

If length is provided, zero-termination is ignored and the result can contain NUL characters.

If length is not provided, the returned string is the string up til but not including the first NUL character.


String toDartString({int? length}) {
  final codeUnits = cast<Uint8>();
  if (length != null) {
    RangeError.checkNotNegative(length, 'length');
  } else {
    length = _length(codeUnits);
  return utf8.decode(codeUnits.asTypedList(length));