NIB / DOCUMENTATION
Toggle group — NibComponents
Press one style or combine several without inventing a controller.
Open interactive viewAllow a single choice to be cleared
The default constructor requires options and nullable value. Pressing the active segment emits null, so this is useful for optional formatting. A radio group is a better fit when choosing an option should never toggle it off.
Combine values with the named constructor
NibToggleGroup.multiple takes a required Set<T> values and a ValueChanged<Set<T>> callback. Treat the emitted set as the next state. The demo stores its selected styles in a sorted comma-separated settings string so copied configuration matches the preview.
NibToggleGroup<String>.multiple(
options: const [NibToggleOption(value: 'bold', label: 'Bold'),
NibToggleOption(value: 'italic', label: 'Italic')],
values: styles, onChanged: (next) => setState(() => styles = next),
)Give each segment a name
NibToggleOption requires value and at least label or icon. An icon-only option also requires semanticLabel. disabled applies to one segment; the group-level disabled flag blocks all. Each segment is a real NibButton and shares NibButtonSize presets.
Separate focus from activation
There is one tab stop. Arrows move focus, wrap, and skip disabled segments without changing selection. Enter or Space toggles the focused segment. Test this distinction if replacing a radio group with toggle segments.
Wrap naturally or share a bounded width
direction defaults to horizontal and wraps narrow content. Vertical mode stacks segments. itemWidth fixes each segment width; fillWidth gives horizontal segments equal shares and requires a finite parent width. spacing defaults to 8. animated pops a newly selected segment and defaults to false.
A selection disappears or a row overflows
An active single segment deliberately toggles back to null. Use a radio group if that behavior is wrong for your task. Avoid fillWidth inside an unbounded horizontal scroll view; give the group a finite width or let its segments wrap.