utf8Convert method Null safety

String utf8Convert(
  1. List<int> bytes
)

Convert bytes to human readable string while removing non-ascii characters @param bytes: List @return String

Implementation

String utf8Convert(List<int> bytes) {
  List<int> utf8Lines = List<int>.from(bytes);
  bool running = true;
  int i = 0;
  while (running) {
    // Check end of string
    if (utf8Lines.length == i) {
      running = false;
      break;
    }
    // Remove non-ascii/unnecessary utf8 characters but keep newline (10)
    if (utf8Lines[i] != 10 && (utf8Lines[i] < 32 || utf8Lines[i] > 122)) {
      utf8Lines.removeAt(i);
      continue;
    }
    i++;
  }
  return utf8.decode(utf8Lines);
}