What is the GetX CLI?
The GetX CLI is a command‑line tool that automates the creation of common GetX files: controllers, views, bindings, and full pages. It follows the modular structure recommended by GetX, saving you time and enforcing consistency. By using the CLI, you can generate boilerplate code with a single command, keeping your development workflow fast and organized.
Installation
The GetX CLI is a Dart package that you can install globally. Run the following command in your terminal:
After activation, you may need to add the global Dart bin to your PATH. The CLI will show instructions. You can verify the installation with:
Creating a New Project
The CLI can create a new Flutter project already set up with GetX and a recommended folder structure. Navigate to the directory where you want your project and run:
This creates a new Flutter project named my_app with GetX dependencies, an initial binding, and a home module. You can also create a project without a module using get create project:my_app --no-module.
Generating Modules
The core concept of GetX CLI is the module. A module is a self‑contained feature that includes its own controller, view, binding, and optionally model. To generate a new module, run:
This creates a folder product inside lib/app/modules/ with:
product_controller.dartproduct_page.dart(the view)product_binding.dart
The CLI also automatically registers the module in app_routes.dart and app_pages.dart.
Generating Individual Components
You can generate individual files without creating a full module:
Each command creates the corresponding file in the appropriate directory (e.g., lib/app/controllers/user_controller.dart).
Generating a Full Page with All Components
For a complete screen, use the page command. It creates the controller, view, binding, and updates the route files automatically. You can also pass options to create a model or a service.
Generating Services
Services (extending GetxService) can be generated with:
Generating Providers / Repositories
For data layers, you can generate providers (e.g., API clients) and repositories:
Customizing the Structure
The CLI uses templates stored in the get_cli package. You can override them by creating a .get_cli folder in your project root and placing custom templates there. This allows you to tailor the generated files to your own coding style.
Updating Routes Automatically
When you generate a page with get create page, the CLI adds the route to app_pages.dart and app_routes.dart automatically. You can also manually update routes with:
Getting Help
To see all available commands, run:
Best Practices
- Use modules for each feature – Keep related files together.
- Use the CLI to enforce consistency – Everyone on the team follows the same structure.
- Customize templates – Adapt the generated code to your project's conventions.
- Commit generated files – The generated code is part of your source control; don't ignore it.
- Run
get update pagesafter manual route changes – Keeps the route list consistent.
Common Mistakes
- ❌ Running commands outside the project root – The CLI needs to be in a Flutter project directory.
✅
cdinto your project first. - ❌ Forgetting to import generated files – The CLI may not add imports if you generate individual components. ✅ Manually import when needed.
- ❌ Using the CLI without version control – Generated files can be overwritten; commit changes to track them.
- ❌ Over‑generating – Not every widget needs its own module. Use the CLI for full features, not for tiny components.
Conclusion
The GetX CLI is a powerful tool that automates repetitive tasks and enforces a consistent architecture. By using it, you can focus on business logic instead of boilerplate, and ensure your project follows GetX best practices from the start.