Skip to content

Instantly share code, notes, and snippets.

@bschulz87
Last active July 1, 2024 14:14
Show Gist options
  • Save bschulz87/727b483b2ea6b0beb9407e6e51235621 to your computer and use it in GitHub Desktop.
Save bschulz87/727b483b2ea6b0beb9407e6e51235621 to your computer and use it in GitHub Desktop.
Storybook Riverpod Knob
extension on Iterable<(String, Override)> {
List<Option> toKnobOptions() => List<Option>.from(map((e) => Option(label: e.$1, value: e)));
}
final knobOverride = Story(
name: "Knob/Override",
builder: (context) {
final options = [
(
"Loading",
getLocalPathFromStorageFile.overrideWith((_, __) async {
await Future.delayed(const Duration(days: 365));
throw UnimplementedError();
}),
),
(
"Error",
getLocalPathFromStorageFile.overrideWith((_, __) async => throw Exception("Something failed")),
)
];
final overrides = context.knobs.options(
label: "State",
initial: options[0],
options: options.toKnobOptions(),
return ProviderScope(
key: Key(overrides.$1),
overrides: [overrides.$2],
child: const Placeholder());
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment