chooseOneSync<T extends Object?> method
T
chooseOneSync<T extends Object?>(})
Like chooseOne, but blocks and returns the answer.
Implementation
T chooseOneSync<T extends Object?>(
String? message, {
required List<T> choices,
T? defaultValue,
String Function(T choice)? display,
}) {
if (choices.isEmpty) {
throw ArgumentError.value(choices, 'choices', 'must not be empty');
}
final labels = [for (final c in choices) display?.call(c) ?? '$c'];
final start =
defaultValue == null ? 0 : max(0, choices.indexOf(defaultValue));
int? selectedIndex;
_askSync(
'chooseOneSync',
() => promptSelectSync(labels,
title: '$message', initial: start, options: _options),
onSelection: (indices) => selectedIndex = indices.single,
);
return choices[selectedIndex ?? start];
}