chooseSync method
T
chooseSync()
Implementation
T chooseSync() {
final buff = StringBuffer();
int i = -1;
for (final choice in choices) {
i++;
buff.writeln(formatter(choice, i + 1));
}
buff.write(message);
for (;;) {
final input = DCPrompter(console: console, message: buff.toString(),).prompt_sync();
final result = _parseInteger(input ?? '');
if (result == null && input != null) {
final exists = choices
.map(
(final it) => it.toString().trim().toLowerCase(),
)
.contains(
input.trim().toLowerCase(),
);
if (exists) {
final val = choices.firstWhere(
(final it) {
return it.toString().trim().toLowerCase() == input.trim().toLowerCase();
},
);
return val;
}
}
try {
if (result != null) {
return choices[result - 1];
}
// ignore: empty_catches, avoid_catches_without_on_clauses
} catch (e) {}
}
}