promptYesNo static method

Future<bool> promptYesNo(
  1. String message
)

Prompt user with a yes/no question Returns true for yes, false for no

Implementation

static Future<bool> promptYesNo(String message) async {
  while (true) {
    stdout.write('$message ');
    final input = stdin.readLineSync()?.toLowerCase().trim() ?? '';

    // Default to yes if empty input
    if (input.isEmpty || input == 'y' || input == 'yes') {
      return true;
    }

    if (input == 'n' || input == 'no') {
      return false;
    }

    // Invalid input, ask again
    print('Please enter Y (yes) or N (no)');
  }
}