Flutter - Important CLI commands - GeeksforGeeks

09 Jul, 2021
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.
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. 
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.
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.
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.
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.
Syntax:  flutter pub update
This command will update the flutter packages used in the current project.
Syntax: flutter --help --verbose 
This is a very useful command, especially for beginners. It shows a list of all the commands flutter uses.
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.
Syntax:  flutter version
It shows the version related information for flutter and dart SDKs.
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.
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.
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.
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.
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.
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. 
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.
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.
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.
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.
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.
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.
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.
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.
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.
Syntax: flutter precache <ARGUMENTS> 
This command is to get all the assets that our flutter app is using present locally or globally. 
surinderdawra388
Articles
TechTips
Web Technologies
Web technologies Questions
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Time Complexity and Space Complexity
Docker - COPY Instruction
Time complexities of different data structures
SQL | Date functions
Difference between Min Heap and Max Heap
How to Find the Wi-Fi Password Using CMD in Windows?
How to Run a Python Script using Docker?
Docker - COPY Instruction
Setting up the environment in Java
How to setup cron jobs in Ubuntu