If you are using Widgetbook Cloud Review, you can now create multiple snapshots for a single use case. This feature is useful for testing different states of your use case using various addon or knob configurations, rather than just the default configuration.
- Open the main file of your app where your Widgetbook's
@Appannotation is defined.
-
Select the addons you want to test and include them, such as Themes and Languages. The following
AddonConfigclasses are available:
Add the configurations matrix to the cloudAddonsConfigs parameter of the @App annotation. For example, to test German in dark mode and English in light mode, both on an iPhone 12 viewport:
dart
@App(
cloudAddonsConfigs: {
'German Dark': [
ViewportAddonConfig(IosViewports.iPhone12),
LocalizationAddonConfig('de'),
ThemeAddonConfig('Dark'),
],
'English Light': [
ViewportAddonConfig(IosViewports.iPhone12),
LocalizationAddonConfig('en'),
ThemeAddonConfig('Light'),
],
},
)
class WidgetbookApp extends StatelessWidget {
const WidgetbookApp({super.key});
@override
Widget build(BuildContext context) {
return Widgetbook.material(...);
}
}- Open the file where your use case is defined.
- Add the configurations matrix to the
cloudKnobsConfigsparameter of the@UseCaseannotation. For example, to test two common variants of the use case:
dart
@UseCase(
name: 'Default',
type: Button,
cloudAddonsConfigs: {
'Disabled Long Text Without Badge': [
BooleanKnobConfig('enabled', false),
StringKnobConfig('text', 'This is a very very long text for a button that might cause overflow'),
NullKnobConfig('badge'),
],
'Enabled Short Text With Badge': [
BooleanKnobConfig('enabled', true),
StringKnobConfig('text', 'Button'),
IntKnobConfig('badge', 1),
],
},
)
Widget buildButtonUseCase(BuildContext context) {
return Button(
text: context.knobs.string(label: 'text'),
enabled: context.knobs.boolean(label: 'enabled'),
badge: context.knobs.intOrNull(label: 'badge'),
);
}
