The Barrel Generator is a CLI tool written in Go that automates the creation of export files (barrel files) for Dart/Flutter projects. It scans a directory and generates a <folder_name>_exports.dart file containing all necessary exports, organized automatically.
If you already have Go installed, you can compile the binary directly:
# Clone the repository
git clone <REPOSITORY_URL>
cd <PROJECT_FOLDER>
# Compile the binary
go build -o barrel_gen
# Move it to a globally accessible location
mv barrel_gen ~/go/bin/ # Or sudo mv barrel_gen /usr/local/bin/Now, you can run the barrel_gen command from anywhere in the terminal.
The Barrel Generator allows you to create export files for any folder in your Dart/Flutter project.
barrel_gen -dir=lib/features/user/modelsIf the models folder contains .dart files, it will generate:
lib/features/user/models/models_exports.dart
barrel_gen -dir=lib/features/user/models -o=lib/features/user/models.dartThis will create a file with a different name:
lib/features/user/models.dart
If we run:
barrel_gen -dir=lib/modelsAnd the lib/models folder contains the following files:
lib/models/
│── user.dart
│── product.dart
│── order.dart
│── user.freezed.dart (ignored)
│── user.g.dart (ignored)
The generated models_exports.dart file will be:
// 📦 Automatically generated file. DO NOT EDIT MANUALLY.
export 'user.dart';
export 'product.dart';
export 'order.dart';✔ Automatically generates a <folder_name>_exports.dart file
✔ Allows setting a custom output name with -o
✔ Ignores generated files (.freezed.dart, .g.dart)
✔ Automatically sorts exports
✔ Color-coded logs for better feedback
Organizing your files in Flutter has never been easier! 🚀