# Widgetbook v3 to v4 Migration Prompt Use this prompt to migrate a Flutter project from Widgetbook v3 to v4 in a safe, repeatable way. ## Role You are a migration assistant. Your job is to: 1. Analyze the existing v3 codebase. 2. Apply v4 migration changes with minimal disruption. 3. Preserve behavior and story coverage. 4. Return a clear migration report. Do not invent APIs. Prefer established v4 patterns shown below. ## Inputs You Should Inspect - `pubspec.yaml` - Widgetbook entrypoint and config files - Story / use-case files (especially use of `@UseCase`, knobs, and `cloudKnobsConfigs`) - Custom wrappers and mocks in use-cases - Existing tests and golden test setup ## Migration Workflow ### Phase 1 — Dependencies Update `pubspec.yaml`: - Remove `widgetbook_annotation` - Remove `widgetbook_generator` - Update `widgetbook` to `^4.0.0-beta.1` or later Then run dependency resolution (e.g. `flutter pub get`) commands used by the project. ### Phase 2 — App Bootstrap and Config #### 2.1 Entry Point **v3** ```dart void main() { runApp(const WidgetbookApp()); } ``` **v4** ```dart void main() => runWidgetbook(config); ``` #### 2.2 Config Structure **v3** ```dart import 'main.directories.g.dart'; @App(...) class WidgetbookApp extends StatelessWidget { @override Widget build(BuildContext context) { return Widgetbook( directories: directories, appBuilder: ..., addons: [...], ); } } ``` **v4** ```dart import 'components.g.dart'; final config = Config( components: components, appBuilder: ..., addons: [...], ); ``` #### 2.3 Theme Addon Migration **v3** ```dart ThemeAddon( themes: [ WidgetbookTheme(name: 'Light', data: AppThemeData.light), WidgetbookTheme(name: 'Dark', data: AppThemeData.dark), ], themeBuilder: (context, theme, child) => AppTheme(data: theme, child: child), ) ``` **v4** ```dart ThemeAddon( { 'Light': AppThemeData.light, 'Dark': AppThemeData.dark, }, (context, theme, child) => AppTheme(data: theme, child: child), ) ``` #### 2.4 Locale Addon Migration **v3** ```dart LocalizationAddon( locales: AppLocalizations.supportedLocales, localizationsDelegates: AppLocalizations.localizationsDelegates, initialLocale: AppLocalizations.supportedLocales.last, ) ``` **v4** ```dart LocaleAddon( AppLocalizations.supportedLocales, AppLocalizations.localizationsDelegates, ) ``` #### 2.5 Cloud Addons Config → Scenarios **v3** ```dart @App( cloudAddonsConfigs: { 'German Light': [ LocalizationAddonConfig('de'), ThemeAddonConfig('Light'), ], }, ) ``` **v4** ```dart final config = Config( scenarios: [ ScenarioDefinition( name: 'German Light', modes: [ LocaleMode(const Locale('de')), ThemeMode( 'Light', AppThemeData.light, (context, theme, child) => AppTheme(data: theme, child: child), ), ], ), ], ); ``` ### Phase 3 — Story Migration #### 3.1 Core Concepts to Rename | v3 | v4 | | --------------------- | ----------------- | | Use-case | Story | | `*.dart` | `*.stories.dart` | | `@UseCase` annotation | `Meta` + `_Story` | | `context.knobs.*` | `*Arg` classes | | `cloudKnobsConfigs` | `scenarios` | #### 3.2 Simple Story Conversion **v3** ```dart // button.dart @UseCase( name: 'Default', type: Button, designLink: 'https://www.figma.com/...', ) Widget buildButtonCase(BuildContext context) { return Button( content: context.knobs.string( label: 'content', initialValue: 'Button', ), ); } ``` **v4** You need to run `dart run build_runner build` after this change to generate the `button.stories.g.dart`. ```dart // button.stories.dart part 'button.stories.g.dart'; const meta = Meta