Open In App

Flutter - Important CLI commands

Last Updated : 30 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

When developing apps in Flutter, understanding the essential Flutter CLI commands can significantly streamline your workflow. These important Flutter commands allow developers to interact with the framework directly from the terminal, speeding up tasks like building, running, and debugging apps. Whether you're a beginner or an experienced developer, mastering these Flutter command-line tools will help you manage your projects efficiently. This guide will cover the most useful Flutter commands to enhance your productivity.

 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 testing 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 that 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 a directory then it will build inside the build folder. We can build a web app with the flutter build web command, an Android app with the flutter build app or flutter build app bundle (more preferred), and an iOS app with the flutter build iOS command.

12. List Connected Devices:

Syntax: flutter devices -d <DEVICE_ID>

This is the command to list all the connected devices 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 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 the 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 that gets generated when an app crashes.

17. Configure Functionalities:

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

This command is to configure the functionalities of Flutter that 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 accesses some hardware from the user's device which requires the application of some drivers, then this is the command we should run to test if our drivers are running well without errors.

20. List available Emulators:

Syntax: flutter emulators

This command lists all the emulators currently installed on our machine and 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 a built-in application such as an 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 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. 

Flutter---Important-CLI-commands-
Flutter - Important CLI commands

Conclusion

By incorporating these Flutter CLI commands into your development workflow, you can perform critical tasks with ease and efficiency. From setting up projects to debugging, the important Flutter commands outlined in this guide will help you streamline your development process. Whether you're using Flutter build commands or managing your app with Flutter run commands, mastering the command-line interface is key to becoming a more efficient Flutter developer.


Next Article

Similar Reads