Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow addKnob to be called from outside #130

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions packages/storybook_flutter/lib/src/plugins/knobs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class KnobsNotifier extends ChangeNotifier implements KnobsBuilder {
return _knobs[story.name]?.values.toList() ?? [];
}

T _addKnob<T>(Knob<T> value) {
/// Allows to add a knob to the current story.
/// Using the convenience functions (boolean, text, ...) is recommended.
T addKnob<T>(Knob<T> value) {
// ignore: avoid-non-null-assertion, having null here is a bug
final story = _storyNotifier.currentStory!;
final knobs = _knobs.putIfAbsent(story.name, () => {});
Expand All @@ -143,7 +145,7 @@ class KnobsNotifier extends ChangeNotifier implements KnobsBuilder {
String? description,
bool initial = false,
}) =>
_addKnob(
addKnob(
Knob(
label: label,
description: description,
Expand All @@ -159,7 +161,7 @@ class KnobsNotifier extends ChangeNotifier implements KnobsBuilder {
String? description,
String initial = '',
}) =>
_addKnob(
addKnob(
Knob(
label: label,
description: description,
Expand All @@ -176,7 +178,7 @@ class KnobsNotifier extends ChangeNotifier implements KnobsBuilder {
required T initial,
List<Option<T>> options = const [],
}) =>
_addKnob(
addKnob(
Knob(
label: label,
description: description,
Expand All @@ -195,7 +197,7 @@ class KnobsNotifier extends ChangeNotifier implements KnobsBuilder {
double max = 1,
double min = 0,
}) =>
_addKnob(
addKnob(
Knob(
label: label,
description: description,
Expand All @@ -216,7 +218,7 @@ class KnobsNotifier extends ChangeNotifier implements KnobsBuilder {
int min = 0,
int divisions = 100,
}) =>
_addKnob(
addKnob(
Knob(
label: label,
description: description,
Expand Down Expand Up @@ -249,7 +251,7 @@ class _NullableKnobsBuilder extends NullableKnobsBuilder {
bool initial = false,
bool enabled = true,
}) =>
_knobs._addKnob(
_knobs.addKnob(
NullableKnob(
enabled: enabled,
label: label,
Expand All @@ -268,7 +270,7 @@ class _NullableKnobsBuilder extends NullableKnobsBuilder {
List<Option<T>> options = const [],
bool enabled = true,
}) =>
_knobs._addKnob(
_knobs.addKnob(
NullableKnob(
enabled: enabled,
label: label,
Expand All @@ -289,7 +291,7 @@ class _NullableKnobsBuilder extends NullableKnobsBuilder {
double min = 0,
bool enabled = true,
}) =>
_knobs._addKnob(
_knobs.addKnob(
NullableKnob(
enabled: enabled,
label: label,
Expand All @@ -313,7 +315,7 @@ class _NullableKnobsBuilder extends NullableKnobsBuilder {
bool enabled = true,
}) =>
_knobs
._addKnob(
.addKnob(
NullableKnob(
enabled: enabled,
label: label,
Expand All @@ -336,7 +338,7 @@ class _NullableKnobsBuilder extends NullableKnobsBuilder {
String initial = '',
bool enabled = true,
}) =>
_knobs._addKnob(
_knobs.addKnob(
NullableKnob(
enabled: enabled,
label: label,
Expand Down
Loading