Skip to content
Related Articles
Open in App
Not now

Related Articles

Flutter – Important CLI commands

Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 09 Jul, 2021
Improve Article
Save Article

Flutter is a mobile development UI kit managed by Google. It is powered by dart language which is used for the Flutter framework to make applications for mobile, web, and desktop with a single codebase. Flutter Command-Line (CLI) tool enables a user to interact with flutter SDK. 

In this article, we are going to discuss all the commands flutter uses. We will see the most important commands which are used in almost all flutter projects with their explanation.

 1. Create an App:

Syntax: flutter create APP_NAME 

This command creates a new flutter app project, in the current directory. If you want to create the project in a specific folder then move to that directory first using the command cd FILE  ADDRESS

2. Analyze the Dart Code:

Syntax: flutter analyze -d <DEVICE_ID>

This command performs a static analysis of the project’s Dart source code. Basically what it does is search for any missing code or errors. It can be performed for a specific file or the whole flutter project.

3. Test Flutter App:

Syntax: flutter test [<DIRECTORY|DART_FILE>] 

This command performs a test on the flutter project or a specific dart file. It checks if the application or code is flawed or not. This is very useful if our application is big and test it manually is not possible.

4. Run a Dart file:

Syntax: flutter run <DART_FILE>

This command will run the dart file if mentioned or otherwise it will run the whole project in the device which the user chooses.

5. Download Dependencies/Packages:

Syntax: flutter pub get

This command downloads all the packages or dependencies which are listed in the pubspeck.yaml file of the current or active project file.

6. Update Flutter packages:

Syntax:  flutter pub update

This command will update the flutter packages used in the current project.

7. Get Help:

Syntax: flutter --help --verbose 

This is a very useful command, especially for beginners. It shows a list of all the commands flutter uses.

8. Check Project Health:

Syntax: flutter doctor

This command will check the current status of the flutter information. If some software is missing or not working then it will show a warning.

9. Check Version:

Syntax:  flutter version

It shows the version related information for flutter and dart SDKs.

10. Check Channels:

Syntax:  flutter channel <CHANNEL_NAME>

This command will list all the flutter channels available right now. You can see which one you are using or switch to another to access new features. Generally stable is the one most people use.

11. Build the Project:

Syntax: flutter build <DIRECTORY>

This command is to build the flutter application in the directory we want. If we don’t assign directory then it will build inside the build folder. We can build web app with flutter build web command, an android app with flutter build apk or flutter build appbundel (more preferred), and an iOS app with flutter build ios command.

12. List Connected Devices:

Syntax: flutter devices -d <DEVICE_ID>

This is the command to list all the connected device on which we can run our flutter application. Then we can connect to the device of our choice to run the flutter application.

13. Upgrade Flutter Version:

Syntax:  flutter upgrade 

This command should be run globally in the system. It upgrades the copy of flutter SDK along with dart SKD in our machine. It is usually a good idea to run this command after every new release.

14. Get necessary Packages for Project:

Syntax:  flutter assemble -o <DIRECTORY>

This command fetches all the necessary package uses in the app (if not present already) and then builds the app.

15. Add Pre-existing Flutter App:

Syntax: flutter attach -d <DEVICE_ID>

This command is similar to the flutter run command, but it provides certain other terminal functionalities other than what’s present in the flutter run command when we are adding flutter to the app made using another framework. This Command should be used when we are adding flutter to a pre-existing application, if we simply give flutter run command then we will not get hot reload, DevTools and other functionalities. 

16.  Work with Stack Track file:

Syntax: flutter symbolize --input=<STACK_TRACK_FILE>

This command is used to make stack trace human-readable. The stack trace could be a file which gets generated when an app crashes.

17. Configure Functionalities:

Syntax: flutter config --build-dir=<DIRECTORY>

This command is to configure the functionalities of flutter which you want in your project. Such as you can enable or disable flutter web.

18. Downgrade Flutter/Dart SDKs:

Syntax: flutter downgrade

This command should be run globally in the system. It downgrades the copy of flutter SDK along with dart SKD in our machine to the previously available active version. This can be done if something in the present version of flutter is not working for you the way it should.

19. Work with Connected Device Hardware:

Syntax:  flutter drive

If our flutter project access some hardware from the user’s device which requires the application of some drivers, then this is the command we shout run to test if our drivers are running well without and errors.

20. List available Emulators:

Syntax: flutter emulators

This command lists all the emulators currently installed in our machine gives us the option to launch the emulator and create a new emulator if we want.

21.  Format Dart file:

Syntax: flutter format <DART_FILE | DIRECTORY>

This flutter command formats the dart file according to the pre-specified setting in the flutter SDK. But if you are using VS-Code or Android Studio with the flutter and dart extensions installed, then the dart is formatted automatically.

22. Get Dependencies locally:

Syntax: flutter gen-l10n <DIRECTORY>

This command is used to generate a local file of flutter dependencies. For example, if we are using certain fonts of mages through an API this command will make them available locally. For all the options use this command flutter gen-l10n -h.

23. Install Flutter App on a Device:

Syntax:  flutter install -d <DEVICE_ID>

This is the command to install the flutter application on an attached device after building the application. The attached device can either be a physical one such as an android or iOS mobile or build in applications such as emulator or browser.

24. View Terminal logs:

Syntax:  flutter logs

This command shows us the log output in the terminal for running the flutter application. It is usually used to if some code in the app is breaking or giving exceptions.

25. List Project Assets:

Syntax: flutter precache <ARGUMENTS> 

This command is to get all the assets that our flutter app is using present locally or globally. 

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!