askYesNo static method
Prompts the user with a yes/no question and reads a confirmation from stdin.
Implementation
static bool askYesNo(String question, {bool defaultValue = true}) {
final options = defaultValue ? '[Y/n]' : '[y/N]';
stdout.write('$question $options: ');
final input = stdin.readLineSync()?.trim().toLowerCase();
if (input == null || input.isEmpty) {
return defaultValue;
}
if (input == 'y' || input == 'yes') {
return true;
}
if (input == 'n' || input == 'no') {
return false;
}
// Invalid input, prompt again
return askYesNo(question, defaultValue: defaultValue);
}