The iterable segmented knob allows you to dynamically enter an iterable value for a widget property in the Widgetbook UI.
This is particularly useful for properties that require an iterable input, such as a List or Set of item.
The iterable knob has two variants:
context.knobs.iterable.segmented(): This variant allows you to enter an iterable value via a segmented button. It does not acceptnullvalues.context.knobs.iterableOrNull.segmented(): This variant allows you to enter an iterable value via a segmented button or set the value tonull. It is useful when the property can be optional.
In addition to the knob's base properties, the iterable segmented knob includes the following:
The options shown in the segmented buttons. The type of the options must be the same as the type of the property.
A function to format the options for display in the segmented buttons.
To use the iterable segmented knob, call the context.knobs.iterable.segmented() method.
@UseCase(type: MyWidget, name: 'Default')
Widget buildUseCase(BuildContext context) {
return MyWidget(
status: context.knobs.iterable.segmented(
label: 'status',
labelBuilder: (value) => value!.name,
options: [
OnlineStatusType.online,
OnlineStatusType.offline,
OnlineStatusType.busy,
],
),
);
}
enum OnlineStatusType { online, offline, busy }To use the nullable iterable segmented knob, call the context.knobs.iterableOrNull.segmented() method.
@UseCase(type: MyWidget, name: 'Default')
Widget buildUseCase(BuildContext context) {
return MyWidget(
status: context.knobs.iterableOrNull.segmented(
label: 'status',
labelBuilder: (value) => value!.name,
options: [
OnlineStatusType.online,
OnlineStatusType.offline,
OnlineStatusType.busy,
],
),
);
}
enum OnlineStatusType { online, offline, busy }Multi-snapshot support for Widgetbook Cloud allows you to generate multiple screenshots of a single use case with varying values using KnobsConfigs and AddonsConfigs. Please refer to the IterableKnobConfig page for more information.

