Integer Knob

The integer input knob renders a text field in the Widgetbook UI where you can dynamically enter an int value for a widget property. This is particularly useful for properties that require an integer input, such as shown in a notification badge.

Varients

The integer input knob has two variants:

  • context.knobs.int.input(): This variant allows you to enter an integer value via a text field. It does not accept null values.
  • context.knobs.intOrNull.input(): This variant allows you to enter an integer value via a text field or set the value to null. It is useful when the property can be optional.
Widgetbook also offers support for slider-based integer knobs which are documented on the Integer Slider Knob page.

Properties

Besides the knob's base properties, the integer input knob does not feature any additional properties.

context.knobs.int.input()

Example

Usage

To use the integer input knob, call the context.knobs.int.input() method.

Example: Integer Input Knob
@UseCase(type: MyWidget, name: 'Default')
Widget buildUseCase(BuildContext context) {
  return MyWidget(
    count: context.knobs.int.input(label: 'count', initialValue: 100), 
  );
}

context.knobs.intOrNull.input()

Example

Usage

To use the nullable integer input knob, call the context.knobs.intOrNull.input() method.

Example: Nullable Integer Input Knob
@UseCase(type: MyWidget, name: 'Default')
Widget buildUseCase(BuildContext context) {
  return MyWidget(
    count: context.knobs.intOrNull.input(label: 'count'), 
  );
}

Multi-snapshot Support

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 IntKnobConfig page for more information.