Last active
July 1, 2024 14:14
-
-
Save bschulz87/727b483b2ea6b0beb9407e6e51235621 to your computer and use it in GitHub Desktop.
Storybook Riverpod Knob
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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