handleKey method Null safety

void handleKey(
  1. List<int>? bytes,
  2. String? name
)

Implementation

static void handleKey(List<int>? bytes, String? name) {
  if (name == null) {
    return;
  }

  if (_handlers.containsKey(name)) {
    _handlers[name]!.add(name);
    return;
  }

  if (!echoUnhandledKeys) {
    return;
  }

  if (bytes == null) {
    return;
  }

  if (bytes.length == 1 && bytes[0] == 127) {
    if (Platform.isMacOS) {
      Console.moveCursorBack(1);
    } else {
      stdout.write('\b \b');
      return;
    }
  }

  stdout.add(bytes);

  if (bytes.length == 1 && bytes[0] == 127) {
    Console.moveCursorBack(1);
  }
}