packed 0.2.2
packed: ^0.2.2 copied to clipboard
A CLI tool to rapidly generate Flutter feature structures following the BLoC pattern.
Packed CLI 📦 #
A powerful CLI tool to rapidly generate Flutter feature structures following Clean Architecture and the BLoC/Cubit pattern. Stop wasting time on boilerplate and focus on building features.
🚀 Features #
- 🏗️ Clean Architecture: Automatically generates Data, Domain, and Presentation layers.
- 📦 Auto-Dependencies: Automatically installs
flutter_bloc,get_it,equatable, anddartzif they are missing. - 💉 Dependency Injection: Automatic
get_itregistration for all layers (Datasources, Repositories, Usecases, and Cubits). - 🧩 Modular Structure: Each feature is self-contained with its own DI file for better maintainability.
- ⚡ Standalone Usecases: Generate new usecases for existing features with automatic DI registration.
- 📏 Smart Naming: Automatically handles
snake_casefor files andPascalCasefor classes.
📥 Installation #
# From pub.dev
dart pub global activate packed
🛠️ Usage #
1. Initialize Project #
Sets up the core folder structure (lib/core/), base classes (Failures, UseCases), and a global Dependency Injection container.
packed generate init
This command will create:
lib/core/error/failures.dartlib/core/usecases/usecase.dartlib/core/network/network_info.dartlib/injection_container.dart
2. Generate a New Feature #
Generates a complete Clean Architecture folder structure with all necessary boilerplate code.
packed generate feature <feature_name>
Example:
packed generate feature Home
Generated Structure:
lib/features/home/
├── data/
│ ├── datasources/home_remote_datasource.dart
│ ├── models/home_model.dart
│ └── repositories/home_repository_impl.dart
├── domain/
│ ├── entities/home_entity.dart
│ ├── repositories/home_repository.dart
│ └── usecases/get_home_usecase.dart
├── presentation/
│ ├── cubit/home_cubit.dart & home_state.dart
│ ├── pages/home_page.dart & home_view.dart
│ └── widgets/
└── di/
└── home_di.dart (Dependency Injection)
3. Generate a Standalone Usecase #
Adds a new usecase to an existing feature and automatically registers it in the feature's DI file.
packed generate usecase <usecase_name> <feature_name>
Example:
packed generate usecase UpdateProfile Home
This command will:
- Create
update_profile_usecase.dartinlib/features/home/domain/usecases/. - Add the necessary import to
lib/features/home/di/home_di.dart. - Register
UpdateProfileUseCasein theGetItcontainer within the DI file.
🏛️ Architecture Overview #
🎨 Presentation Layer #
- Cubit: Handles state management using the Cubit pattern.
- Page: The entry point widget that provides the Cubit using
GetIt. - View: The actual UI layout, separated from the Page for better testing and readability.
🌐 Domain Layer #
- Entities: Simple business objects extending
Equatable. - Repositories: Abstract interfaces defining the contract for data operations.
- Usecases: Single-responsibility classes containing business logic.
💾 Data Layer #
- Models: Data Transfer Objects (DTOs) with JSON serialization (extends Entities).
- Datasources: Remote and Local data handling logic.
- Repository Impl: Concrete implementation of domain repositories.
📄 License #
This project is licensed under the MIT License - see the LICENSE file for details.