promptYesNo static method

bool promptYesNo(
  1. String question, {
  2. bool defaultYes = true,
})

Prompts the user with a yes/no question on stdin.

Implementation

static bool promptYesNo(String question, {bool defaultYes = true}) {
  final suffix = defaultYes ? '[Y/n]' : '[y/N]';
  stdout.write('$question $suffix ');
  final input = stdin.readLineSync()?.trim().toLowerCase() ?? '';
  if (input.isEmpty) return defaultYes;
  return input == 'y' || input == 'yes';
}