Introduction to Addons

Addons in Widgetbook provide a flexible and customizable way to enhance your development environment. They allow you to wrap all your use cases with configurable widgets that can be controlled via Widgetbook's UI.

For example, if you want to center all your use cases using the Align widget, you can use the AlignmentAddon instead of manually wrapping each use case.

widgetbook/lib/main.dart
class WidgetbookApp extends StatelessWidget {
  const WidgetbookApp({super.key});

  @override
  Widget build(BuildContext context) {
    return Widgetbook(
      // ...
      addons: [
        // Addons go here...
      ],
    );
  }
}

Order of Addons

The order of addons matters and it will have effect on how the use-case is rendered. The first addon in the list will be the outermost widget, and the last addon will be the innermost widget.

For example, if you are using both AlignmentAddon and ViewportAddon, then the ViewportAddon should always come first, otherwise the AlignmentAddon will be aligning the "viewport" widget itself, and not the use-case inside of it.

widgetbook/lib/main.dart
class WidgetbookApp extends StatelessWidget {
  const WidgetbookApp({super.key});

  @override
  Widget build(BuildContext context) {
    return Widgetbook(
      // ...
      addons: [
        ViewportAddon(Viewports.all), 
        AlignmentAddon() 
      ],
    );
  }
}
Rendered Widget Tree
RootWidget
└── ViewportAddon
  └── AlignmentAddon
    └── UseCaseRenderer
      └── UseCase
        └── Widget