flutter
/

GetX CLI: Supercharge Your Flutter Development

Last Sync: Today

On this page

14
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

flutter

GetX CLI: Supercharge Your Flutter Development

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:

BASHRead-only
1
dart pub global activate get_cli

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:

BASHRead-only
1
get --version

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:

BASHRead-only
1
get create project:my_app

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:

BASHRead-only
1
get create page:product

This creates a folder product inside lib/app/modules/ with:

  • product_controller.dart
  • product_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:

BASHRead-only
1
get create controller:user
get create view:profile
get create binding:settings
get create model:product

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.

BASHRead-only
1
get create page:checkout --model=order --service=payment

Generating Services

Services (extending GetxService) can be generated with:

BASHRead-only
1
get create service:auth

# Or with custom location
get create service:logger --path=lib/services

Generating Providers / Repositories

For data layers, you can generate providers (e.g., API clients) and repositories:

BASHRead-only
1
get create provider:user_api
get create repository:user_repository

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:

BASHRead-only
1
get update pages

Getting Help

To see all available commands, run:

BASHRead-only
1
get --help

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 pages after 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. ✅ cd into 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.

Test Your Knowledge

Q1
of 3

What command installs the GetX CLI globally?

A
flutter pub add get_cli
B
dart pub global activate get_cli
C
npm install -g get_cli
D
pub get get_cli
Q2
of 3

Which command creates a new module with controller, view, and binding?

A
get create module:name
B
get create page:name
C
get create feature:name
D
get create screen:name
Q3
of 3

Where does the CLI place generated modules by default?

A
lib/modules/
B
lib/app/modules/
C
lib/pages/
D
lib/features/

Frequently Asked Questions

Do I need to install anything else besides `get_cli`?

No, the CLI handles everything. It adds GetX to your pubspec.yaml if not present.

Can I use the CLI with an existing GetX project?

Yes, you can run get create page:name inside an existing project, and it will create the files in the expected folders.

Where are files generated?

By default, inside lib/app/. You can change the base path with the --path flag.

How do I remove a generated page?

The CLI doesn't have a delete command. You must manually delete the folder and remove the route references.

Does the CLI support generating tests?

Not directly, but you can create custom templates to generate test files.

Previous

getx rebuild optimization

Next

getx custom rx model

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.