dartgenx 1.5.2
dartgenx: ^1.5.2 copied to clipboard
CLI tool to generate Flutter/Dart boilerplate code.
dartgenx #
A powerful and flexible Command Line Interface (CLI) tool for generating common Flutter/Dart boilerplate code directly into your project. Stop writing the same utility files over and overβlet dartgenx handle the heavy lifting!
β¨ Features #
dartgenx offers both direct command execution and an interactive mode to quickly scaffold necessary services and utilities.
- ApiClient Service: Creates an
api_client.dartfile with dio api calling setup. - Assets Utility Generation: Creates an
assets_utils.dartfile with static paths for all resources in yourassetsfolder. - FCM Service Scaffold: Generates a standard
fcm_service.dartfor handling Firebase Cloud Messaging setup. - Refresh Token Service: Scaffolds a dedicated service for managing token refresh logic.
- Local Storage Service: Creates either
shared_preferences_service.dartorget_storage_service.dartto store data locally. - Sqflite Service: Creates an
sqflite_service.dartto store data locally. - Pagination Utilities: Creates both a
pagination_controller.dartand a reusablepaging_list_view.dartwidget. - Bloc Classes: Creates a basic bloc folder structure with
bloc.dart,state.dartandevent.dartfiles with boilerplate prewritten code. - Getx Classes: Creates a basic getx folder structure with
controller.dart,bindings.dartandscreens.dartfiles with boilerplate prewritten code. - Theme Classes: Creates a basic theme class with
app_colors.dart,app_theme.dartandapp_text_styles.dartfiles with boilerplate prewritten code. - Translate Json Files: Translate JSON values and generate localized JSON file and creates a TranslationKeys class with all the static const keys use for localization.
- Interactive Mode: Use the
dartgenx runcommand for a friendly menu-driven generation experience.
π Installation #
1. Activate the Package #
Activate dartgenx globally using the Dart package manager. This makes the dartgenx command available anywhere on your system.
dart pub global activate dartgenx
2. Verify Installation #
Run the help command to confirm dartgenx is installed and working correctly.
dartgenx --help
π¨βπ» Usage #
There are two primary ways to use dartgenx: Direct Commands and the Interactive Run mode.
1. Interactive Mode (dartgenx run)
For generating multiple files at once or for a guided experience, use the run command.
dartgenx run
This will launch an interactive multi-select menu, allowing you to choose which services you want to generate.
? Select what you have to generate:
[ ] Generate ApiClient [ ] Generate AssetsUtils [ ] Generate FcmService [ ] Generate RefreshToken service [ ] Generate Local Storage service [ ] Generate SqfliteService [ ] Generate Pagination Service [ ] Generate BLoC Service [ ] Generate Getx Service [ ] Generate App icons [ ] Generate Theme class [ ] Translate to another language
2. Direct Commands
Use these commands for quick, single-purpose generation.
| Command | Description | Output File(s) |
|---|---|---|
dartgenx config |
Generates a dartgenx.yaml file for configuring dartgenx cli tool. | dartgenx.yaml |
dartgenx api_client |
Generates a boilerplate service for handling API calls. | lib/api_client.dart |
dartgenx assets |
Scans the assets folder and generates the assets utility file. | lib/assets_utils.dart |
dartgenx fcm |
Generates a boilerplate service for handling FCM. | lib/fcm_service.dart |
dartgenx refresh |
Generates the service for managing refresh token logic. | lib/refresh_token_service.dart |
dartgenx local_storage |
Generates shared_preferences or get_storage service. | lib/shared_preferences_service.dart & lib/get_storage_service.dart |
dartgenx sqflite |
Generates a sqflite singleton service. | lib/sqflite_service.dart |
dartgenx pagination |
Generates a controller and a reusable widget for paginated lists. | lib/pagination_controller.dart & lib/paging_list_view.dart |
dartgenx bloc |
Generate bloc directory which contains bloc.dart, state.dart, and event.dart in lib folder. | From where you run this command or the path you set |
dartgenx getx |
Generate getx directory which contains controllers, bindings, and views in a folder | From where you run this command or the path you set |
dartgenx app-icon |
Generate app icon of different sizes in platform specific folder. | The files are generated at platform specific folders. |
dartgenx theme |
Generate theme class in platform specific folder. | The files are generated at the path provided by you. |
dartgenx translate |
Generate Translation Files and Key class in platform specific folder. | The files are generated at the path provided by you. |
General Help #
To see the list of all available commands:
dartgenx --help
OR #
dartgenx -h
General Version #
To see current installed version on your device:
dartgenx --version
OR #
dartgenx -v
βοΈ Configuration (dartgenx.yaml) #
dartgenx supports project-level configuration using a dartgenx.yaml file.
This file allows you to customize:
- Input paths (assets, translations, app icon)
- Output generation paths
- Folder structure
- Service locations
Place this file in the root of your Flutter project:
example/
βββ lib/
βββ assets/
βββ pubspec.yaml
βββ dartgenx.yaml β
You can generate this file automatically using:
dartgenx config
π Example dartgenx.yaml
# -----------------------------------------------------------------------------
# DartGenX Configuration File
# -----------------------------------------------------------------------------
# This file is used by the DartGenX CLI tool to determine
# default input sources and output generation paths.
#
# Place this file in the root of your Flutter project.
#
# Example location:
# my_flutter_app/dartgenx.yaml
# -----------------------------------------------------------------------------
dartgenx:
# ---------------------------------------------------------------------------
# INPUT PATHS
# ---------------------------------------------------------------------------
# These paths define where DartGenX should read data from.
# These files/folders must already exist inside your project.
# ---------------------------------------------------------------------------
input_path:
# Root assets directory as declared in pubspec.yaml.
# DartGenX will scan this folder to auto-generate asset constants.
assets: assets/
# Path to your main application icon.
# Used for automated app icon handling or configuration generation.
#
# Must be a valid image file (png recommended).
app_icon: assets/icon/logo.png
# ---------------------------------------------------------------------------
# OUTPUT PATHS
# ---------------------------------------------------------------------------
# These paths define where DartGenX will generate files.
# Files will be created automatically if they do not exist.
# ---------------------------------------------------------------------------
output_path:
# API Client base file.
# Used to configure Dio/Base API logic.
api_client: lib/api_service/api_client.dart
# Logger Interceptor file for network debugging.
# Automatically attached to Dio for request/response logging.
logger_interceptor: lib/api_service/interceptor/logger_interceptor.dart
# Utility file for accessing asset paths as constants.
assets_utils: lib/core/utils/assets_utils.dart
# Firebase Cloud Messaging service file.
fcm_service: lib/core/services/fcm_service.dart
# Refresh token handling service.
refresh_token: lib/core/services/refresh_token_service.dart
# Shared Preferences or Get Storage wrapper service.
# Provides strongly typed local storage access.
app_storage_service: lib/core/services/shared_preferences_service.dart
# Sqflite database service file.
sqflite_service: lib/core/services/sqflite_service.dart
# Pagination service folder.
# DartGenX will generate pagination-service files inside this directory.
pagination_service: lib/core/services/
# Theme configuration folder.
theme: lib/core/theme/
translations:
# Source language of the input file (use 'auto' for automatic detection or specify a language code like 'en').
sourceLanguage: auto
# Target languages to translate into using ISO codes (e.g., es=Spanish, mr=Marathi, hi=Hindi).
language: [es, mr, hi]
# Path to the base translation file that will be read.
inputDestination: assets/json/en.json
# Directory where translated files will be generated.
outputDestination: assets/json/
# File extension for generated translation files (default is .json).
outputFileExtension: .txt
# Whether to generate a Dart file containing translation key constants.
generateTranslationKeys: false
# Path where the translation keys Dart file will be created or updated.
translation_keys_location: lib/core/localization/translation_keys.dart
π§ Why Use Configuration?
Using dartgenx.yaml allows you to:
- Maintain consistent architecture across your team
- Customize folder structure
- Support Clean Architecture projects
- Avoid hardcoded generation paths
- Scale your Flutter projects professionally
If the configuration file is missing, dartgenx will fallback to default paths.