Double Knob

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

Variants and Usage

The double 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 double Knob

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

@UseCase(
  type: MyWidget,
  name: 'Default',
  cloudKnobsConfigs: { 
    '0%': [DoubleKnobConfig('value', 0)], 
    '50%': [DoubleKnobConfig('value', 0.5)], 
    '100%': [DoubleKnobConfig('value', 1)], 
  }, 
)
Widget buildUseCase(BuildContext context) {
  return MyWidget(
    value: context.knobs.double.input(label: 'value', initialValue: 0.2),
  );
}

Nullable double 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 value': [NullKnobConfig('value')], 
    'With value': [DoubleKnobConfig('value', 1)], 
  }, 
)
Widget buildUseCase(BuildContext context) {
  return MyWidget(
    value: context.knobs.doubleOrNull.input(label: 'value'),
  );
}