Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

As a Flutter developer, you know that creating complex mobile applications can be a time-consuming and challenging task. The GetX library has been gaining popularity for its simplicity and ease of use, and with the addition of the Get CLI, the development process has become even more streamlined. In this article, we'll dive into the benefits of using the Get CLI and how it can help simplify your workflow, allowing you to focus on creating great apps without getting bogged down in the details. Let's get started!

What is Get CLI?

Get CLI is a powerful command-line interface tool designed to implement the GetX architecture in Flutter. It offers a range of helpful commands that automate common tasks, saving you time and effort. With Get CLI, you can easily manage and organize your Flutter projects using the GetX framework without requiring extensive manual coding.

Installation 

The process of installing Get CLI is straightforward. All you need to do is enter a few commands. In the following sections, I will provide step-by-step instructions for installing Get CLI on both Windows and Mac operating systems.

Windows

To run the command, open your command prompt and type the following command,

dart pub global activate get_cli

The installation process may take some time as it installs all the necessary resources. Please be patient during this time. Once the installation is complete, close the command prompt and enter the following command.

get -v

Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

If you encounter any issues during the installation process on Windows, you can try deactivating Get CLI and downgrading to version 1.6.0. To do this, run the following commands:

dart pub global deactivate get_cli
dart pub global activate get_cli 1.6.0

After executing these commands, restart your computer and enter the following command,

get -v

To verify if Get CLI has been successfully installed and is visible in your command prompt.

Mac

To install the Get CLI on a Mac, you can easily do so by opening the terminal and typing a command,

flutter pub global activate get_cli

Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

The installation process may take some time as it installs all the necessary resources. Please be patient during this time. Once the installation is complete, then add the below line in your .zshrc file.

export PATH = “$HOME/.pub-cache/bin”

Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

After executing these commands, restart your computer and enter the following command,

get -v

Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

Now the installation process is complete, we're good to go.

Create project

To create a new project with Get CLI, open the terminal or Command Prompt where you want to create the project, then type the below commands.

get create project 

Next, it will ask a few questions, and the process will be similar to the image below.

Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

You can open your Flutter project in any code editor of your choice. I'm familiar with Android Studio, so I'll use that. However, you can use any other code editor, such as VS Code - there's no restriction on which editor you can use.

As you can see in the image below, Get CLI has automatically created a file structure for our Flutter project.

Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

Create page

You can create a new page for your application by typing the following command.

get create page:login 

When you hit enter after running the get create module command, Get CLI will create a new login folder under the modules directory. It will also automatically generate bindings, controllers, and views folders for the module, following the GetX pattern.

Additionally, Get CLI will create a new route for the login module. As you can see in the below image,

Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

Create controller

Suppose we're working on our project and require an additional controller file within the login folder. No need to worry, enter the following command, and it will generate a new controller for you:

get create controller:validate on login

You can see in the image below that a validate controller was created under the login folder.

Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

Create view

Similarly, if you want to create an additional view file under the login page, type the following command.

get create view:validate on login

You can see in the image below that a validate view was created under the login folder.

Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

Create model

Creating a model using the Get CLI is as simple as typing the following command:

get generate model from "https://official-joke-api.appspot.com/random_joke"

As shown in the image below, the Get CLI has generated a model file for us and a provider that allows us to perform API operations.

Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

Sometimes, we may not need a provider to be created along with the model. In such cases, we can add the "--skipProvider" flag to our command, as shown below:

get generate model from "https://official-joke-api.appspot.com/random_joke" –skipProvider

Get CLI - The Ultimate Command Line Tool for GetX Architecture in Flutter

Create provider

Creating a provider is a straightforward process with the Get CLI. All you need to do is type the command below, and the provider will be generated for you:

get create provider:login on data

Install package

We can install packages using get cli. Let's say I want to install the flutter_svg package. I will type in the terminal,

get install flutter_svg

In some cases, we need a specific version of a package, so we type the following command:

get install flutter_svg:1.1.1

In case you want to install multiple packages simultaneously, you can use the following command:

get install http camera

By running the above command, both HTTP and camera dependencies will be installed in pubspec.yaml simultaneously.

Remove package

Similarly, we can remove a package from our pubspec.yaml file by typing the following command,

get remove flutter_svg

The following command can be used to remove multiple packages at once,

get remove http camera

Conclusion

In conclusion, if you plan to develop your project with the GetX micro-framework, I highly recommend using the Get CLI tool. Its powerful command-line interface can significantly streamline the development process and save you valuable time. By automating common tasks such as project organization and file structuring, Get CLI allows you to focus on the core functionality of your application. Furthermore, its intuitive interface and customizable features make it an excellent choice for beginners and experienced developers. So, if you want to optimize your workflow and enhance your productivity while working with GetX, Get CLI is an essential tool to consider.

Resources


Similar Articles