promptChoose static method
Implementation
static Future<String> promptChoose(String question, List<String> options) async {
while (true) {
stdout.writeln(question);
for (int i = 0; i < options.length; i++) {
stdout.writeln('${i + 1}. ${options[i]}');
}
stdout.write('Enter the number of your choice: ');
String? input = stdin.readLineSync()?.trim();
int? choice = int.tryParse(input ?? '');
if (choice != null && choice > 0 && choice <= options.length) {
return options[choice - 1];
} else {
stdout.writeln('Invalid choice. Please enter a number between 1 and ${options.length}.');
}
}
}