promptYesNo static method

bool promptYesNo(
  1. String question, {
  2. bool defaultValue = false,
})

Prompt yes/no question

Implementation

static bool promptYesNo(String question, {bool defaultValue = false}) {
  final defaultText = defaultValue ? 'Y/n' : 'y/N';
  stdout.write('$question [$defaultText]: ');

  final input = stdin.readLineSync()?.trim().toLowerCase();

  if (input == null || input.isEmpty) {
    return defaultValue;
  }

  return input == 'y' || input == 'yes';
}