confirm method

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

Asks the user a yes/no question and returns a boolean

Implementation

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

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

  if (input.isEmpty) {
    return defaultValue;
  }

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