Flutter – Project Setup with GetX CLI Tool
In this article, we will learn about how to set up or file structure of our flutter project using get_cli. You might be aware of the GetX state management. If not let us explain to you all the things so that you are familiar with these terms. State Management is to manage the things between 2 or more screens or in a complete app. It helps to create heavy applications and sustain data on every screen. GetX is one of the state management tools, dependency manager, and navigation manager that we are using in Flutter. Previously it was limited to state management only. A command line interface (CLI) is a text-based interface where you can input commands that interact with a computer’s operating system. Let’s learn how to add get_cli in the Flutter project and maintain app structure, dependency and many more. In the time of automation, you should not create the UI structure manually when you can do it through a single command.
Step By Step Implementation
Step 1: Install the get_cli on your device
You can install the CLI in your system
Dart
flutter pub global activate get_cli |
Step 2: Create a flutter project
Create a flutter using the command
Dart
flutter create . |
or you can create a project from get_cli
Dart
get create project |
If you have existing project you can use following command
Dart
get create project |
Step 3: Create a page using command
Create a page that will contain controller, view, and binding with page name that you provide
Dart
get create page:page_name |
It will create a folder like this
It will have view file where you will create a UI like textfiled, text, column, row. Controllers will contain API calls and navigation and data where you will set the data. Bindings are classes where we can declare our dependencies and then ‘bind’ them to the routes. From below command you can manage the app from cli like as now you have access to get command. Let’s understand how to handle different things
1. To generate model file
Dart
get generate model on home with assets/models/user.json |
Here assets/models/user.json is kind of data for which you want to create model file.
2. Add the package
Dart
get install http |
Here http is package name you want to add in your project.
3. To remove the package
This is to remove the package from app
Dart
get remove http |
4. To generate localizations file
Dart
get generate locales assets/locales |
assets/locales is path name where we have to create locales file name
5. To install the dev dependency
Dart
get install flutter_launcher_icons --dev |
6. To update the get_cli
To update the get cli.
Dart
get update |
You have successfully learnt basics of get_cli from the above command. Hope you have understood all the things.