This script automates the integration of Widgetbook into your Flutter project. It scans your lib
directory for all widgets (StatelessWidget
and StatefulWidget
) and generates corresponding Widgetbook use-cases, allowing you to preview them interactively.
- ✅ Automates the setup of a Widgetbook project within a 'widgetbook' directory, streamlining the steps outlined in the Widgetbook Quick Start Guide.
- ✅ Scans your Flutter project's
lib
directory for all widgets. - ✅ Generates use-cases for each widget and saves them in
widgetbook/lib
, preserving the original directory structure. - ✅ Runs
build_runner
to generate the requiredmain.directories.g.dart
file.
You can use curl to download and execute the script in one command:
curl -s https://raw.githubusercontent.com/GianMen91/widgetbook_setup_script/main/widgetbook_setup.sh | bash
curl -s
fetches the script silently.- The
| bash
part pipes it directly into a new Bash process.
- Place the script in the root directory of your Flutter project (same level as
lib
,pubspec.yaml
, etc.). - Open a terminal in the project root.
- Run the script:
bash widgetbook_setup.sh
- Once the script is finished and the setup is complete, navigate to the widgetbook directory:
cd widgetbook
- Run the following command to generate the necessary files:
dart run build_runner build
- Now, start Widgetbook using:
flutter run
During setup, you might see messages about version conflicts or dependency issues. This happens when some packages in your project require different versions to work together.
- If you see a message like "Version solving failed", it means some dependencies need to be adjusted.
- The error message usually suggests a fix (e.g., changing a package version).
-
Check the error message for suggested version changes.
-
If a solution is provided (e.g., updating a package version), run the suggested command.
-
If no suggestion is given, try running:
flutter pub upgrade --major-versions
-
If the issue persists, manually adjust dependency versions in
pubspec.yaml
and then run:flutter pub get
Contributions from users are highly valued and appreciated. Two main ways to contribute to this project are through pull requests and issues.
- Fork the repository and create a branch from the
main
branch. - Make changes or additions to the code.
- Commit the changes, and push them to the branch.
- Open a pull request to the
main
branch with a clear and concise description of the changes.
- Navigate to the Issues section of the repository.
- Check if there is an existing issue similar to the one you'd like to create.
- If there isn't an existing issue, create a new issue by clicking the "New issue" button.
- Provide a descriptive title and detailed information about the proposed changes you want to add to the current script.
Feel free to contribute and share
This project is licensed under the MIT License - see the LICENSE file for details.