storybook_flutter icon indicating copy to clipboard operation
storybook_flutter copied to clipboard

Global knob to have values shared between all stories

Open caiovisk opened this issue 2 years ago • 0 comments

Need to have a Knob that keep its value when changing between stories.

For example, a Font Size options knob that is present on all stories:

context.knobs.options(
      label: 'Font Size',
      initial: '12',
      options: [
        const Option<String>(
          label: '10',
          value: '10',
        ),
        const Option<String>(
          label: '11',
          value: '11',
        ),
        const Option<String>(
          label: '12',
          value: '12',
        ),
        const Option<String>(
          label: '13',
          value: '13',
        ),
        const Option<String>(
          label: '14',
          value: '14',
        )
      ],
    );
Screen Shot 2022-12-19 at 12 23 10 pm

The "issue" is when I select a different value, let's say 11, and navigates to a different story, the "Font Size" knob value gets reset to its initial value. So there is a need to select the knob again.

Is there a way I could declare a global knob of "settings" or have its initial value to be kept between all stories??

caiovisk avatar Dec 19 '22 02:12 caiovisk