build method
Describes the part of the user interface represented by this widget.
Implementation
@override
Widget build(BuildContext context) {
_updateListener();
final optionWidgets = <Widget>[];
final controller = widget.controller;
for (var i = 0; i < controller.options.length; i++) {
if (i > 0) {
optionWidgets.add(const SizedBox(width: 4));
}
final option = controller.options[i];
final isSelected = (controller.selectedIndex == i);
final isFocused = widget.focused && (controller.focusedIndex == i);
final box = isSelected ? '[X]' : '[ ]';
final text = '$box $option';
final style = isFocused
? const Style(modifiers: Modifier.reverse, foreground: Colors.yellow)
: (isSelected
? const Style(
foreground: Colors.yellow,
modifiers: Modifier.bold,
)
: const Style(foreground: Colors.white));
optionWidgets.add(
SizedBox(
width: text.characters.length,
child: Text(text, style: style),
),
);
}
return Row(optionWidgets);
}