fluca 1.0.2
fluca: ^1.0.2 copied to clipboard
FluCA CLI Tool is a developer-friendly command-line interface (CLI) designed to simplify and streamline the process of creating a clean architecture folder structure for Flutter projects. It saves tim [...]
🚀 FluCA CLI Tool #
FluCA CLI Tool is a developer-friendly command-line interface (CLI) designed to simplify and streamline the process of creating a clean architecture folder structure for Flutter projects. It saves time and effort for developers by automating repetitive tasks and generating necessary files with ease.
✨ Features #
- Generate Clean Architecture Structure: Create organized folders and files for clean architecture.
- Dependency Injection with GetIt: Seamlessly integrate the GetIt package for dependency injection.
- Custom File Generation: Generate specific files based on provided options.
- Effortless Setup: Automatically register dependencies in
injection.dartand prepare yourmain.dartfile.
🛠️ Installation #
Install FluCA CLI Tool globally using Dart's pub package manager:
dart pub global activate fluca
Ensure you have Dart and Flutter installed.
🚀 Usage #
Basic Command #
fluca FeatureName
Example:
fluca auth
This generates the following folder and file structure for the feature auth:
features/auth/
├── data/
│ ├── data_sources/auth_data_source.dart
│ ├── models/auth_model.dart
│ ├── repositories/auth_repository_implement.dart
├── domain/
│ ├── entities/auth_entity.dart
│ ├── repositories/auth_repository.dart
│ ├── usecases/auth_usecase.dart
├── presentation/
│ ├── manager/bloc/auth/
│ ├── auth_bloc.dart
│ ├── auth_event.dart
│ ├── auth_state.dart
You will also see a prompt:
Do you want to use GetIt for dependency injection? (yes/no)
- Selecting yes will:
- Add the
get_itpackage to your project. - Generate an
injection.dartfile in thelib/directory.
- Add the
Example of injection.dart: #
import 'features/auth/data/data_sources/auth_data_source.dart';
import 'features/auth/data/repositories/auth_repository_implement.dart';
import 'features/auth/domain/repositories/auth_repository.dart';
import 'features/auth/domain/usecases/auth_usecase.dart';
import 'features/auth/presentation/manager/bloc/auth/auth_bloc.dart';
import 'package:get_it/get_it.dart';
final sl = GetIt.instance;
Future<void> init() async {
await _setUpAuth();
}
Future<void> _setUpAuth() async {
sl.registerFactory(() => AuthBloc());
sl.registerLazySingleton<AuthRepository>(() => AuthRepositoryImplement(dataSource: sl()));
sl.registerLazySingleton(() => AuthUseCase(repository: sl()));
sl.registerLazySingleton<AuthDataSource>(() => AuthDataSourceImplement());
}
You also need to update your main.dart file:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await injection.init();
runApp(const MyApp());
}
Advanced Commands #
Generate Specific Files
- Model and Entity Files:
fluca FeatureName -m file_name
Example:
fluca auth -m admin
Generates:
features/auth/data/models/admin_model.dart
features/auth/domain/entities/admin_entity.dart
- Repository Files:
fluca FeatureName -r file_name
Example:
fluca auth -r admin
Generates:
features/auth/data/repositories/admin_repository_implement.dart
features/auth/domain/repositories/admin_repository.dart
And updates injection.dart:
sl.registerLazySingleton<AdminRepository>(() => AdminRepositoryImplement(dataSource: sl()));
- Data Source File:
fluca FeatureName -d file_name
Example:
fluca auth -d admin
Generates:
features/auth/data/data_sources/admin_data_source.dart
And updates injection.dart:
sl.registerLazySingleton<AdminDataSource>(() => AdminDataSourceImplement());
- Use Case File:
fluca FeatureName -u file_name
Example:
fluca auth -u admin
Generates:
features/auth/domain/usecases/admin_usecase.dart
And updates injection.dart:
sl.registerLazySingleton(() => AdminUseCase(repository: sl()));
- Bloc Files:
fluca FeatureName -bloc file_name
Example:
fluca auth -bloc admin
Generates:
features/auth/presentation/manager/bloc/admin/
├── admin_bloc.dart
├── admin_event.dart
├── admin_state.dart
And updates injection.dart:
sl.registerFactory(() => AdminBloc());
💡 Notes #
- The tool automatically checks for the existence of
injection.dartand updates it accordingly. - Missing dependencies will be generated as needed to ensure smooth integration.
🤝 Contribution #
Feel free to contribute by reporting issues or suggesting improvements via GitHub Issues.
Happy Coding! 🎉