Integer Knob

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

Variants and Usage

The integer knob has two variants with each a regular and a nullable type:

For the usage please refer to the respective pages.

Example Input

Example Slider

Multi-snapshot Support

Multi-snapshot support allows you to generate multiple screenshots of a single use case with varying values using KnobsConfigs and AddonsConfigs.

Regular integer knob

dart
Example: IntegerKnobConfig
import 'package:flutter/material.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart';

@UseCase(
  type: MyWidget,
  name: 'Default',
  cloudKnobsConfigs: { 
    'No notifications': [IntKnobConfig('count', 0)], 
    '3 notifications': [IntKnobConfig('count', 3)], 
    '99+ notifications': [IntKnobConfig('count', 3)], 
  }, 
)
Widget buildUseCase(BuildContext context) {
  return MyWidget(
    count: context.knobs.intOrNull.input(label: 'count'),
  );
}

Nullable integer knob

dart
Example: NullKnobConfig
import 'package:flutter/material.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart';

@UseCase(
  type: MyWidget,
  name: 'Default',
  cloudKnobsConfigs: { 
    'Without count': [NullKnobConfig('value')], 
    'With count': [IntKnobConfig('value', 1)], 
  }, 
)
Widget buildUseCase(BuildContext context) {
  return MyWidget(
    count: context.knobs.doubleOrNull.input(label: 'count'),
  );
}