askYesNo static method

Future<bool> askYesNo(
  1. String question, {
  2. bool defaultValue = true,
})

Ask a yes/no question

Implementation

static Future<bool> askYesNo(String question, {bool defaultValue = true}) async {
  final defaultHint = defaultValue ? '[Y/n]' : '[y/N]';
  stdout.write('$question $defaultHint: ');

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

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

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