Flutter - Important CLI commands
Last Updated :
30 Sep, 2024
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.
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.
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 commandsConclusion
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.
Similar Reads
Container class in Flutter
Container class in flutter is a convenience widget that combines common painting, positioning, and sizing of widgets. A Container class can be used to store one or more widgets and position them on the screen according to our convenience. Basically, a container is like a box to store contents. A bas
8 min read
CLI Commands in NPM
NPM, short for Node Package Manager, is the default package manager for NodeJS. It is a command-line utility that allows you to install, manage, and share packages or modules of JavaScript code. These packages can range from small utility libraries to large frameworks, and they can be easily integra
4 min read
Making Calls in Flutter
In this online world, customer care plays a major role in the success of a company. Users are quite satisfied when they converse with the executives through calls. This has forced companies to add phone numbers to their apps for their customers to contact them easily. But dialing those numbers from
7 min read
Flutter - Copy & Paste From Clipboard
The applications generally involve taking input from users, and users want to paste information from the clipboard, but the application doesn't support it. This can be annoying. To enhance user experience, Flutter developer came up with a package clipboard that allows users to copy text and paste it
2 min read
MaterialApp class in Flutter
MaterialApp Class: MaterialApp is a predefined class or widget in flutter. It is likely the main or core component of a flutter app. The MaterialApp widget provides a wrapper around other Material Widgets. We can access all the other components and widgets provided by Flutter SDK like Text widget, D
7 min read
Flutter - Working with Animations
Whenever building an app animation plays a vital role in designing the experience of the user. People tend to like an app that has a smooth flow and a slick design. The Flutter Package provides a variety of methods to create and use animation in our app. We will be discussing the inbuilt Flutter wid
9 min read
Photo Editing Application in Flutter
With the introduction of the powerful image_editor_plus package, editing images directly within your Flutter app has become significantly more accessible. In this article, we'll dive deep into building a user-friendly image editor app. Users will have the ability to select an image from their camera
7 min read
Mail and SMS in Flutter
The world works in text. From advertisements to conversations, text is everywhere. The most popular modes of official textual communication are Mail followed by SMS. Companies use these modes to communicate not only with their employees but also with their customers. This has led app developers to i
5 min read
Flutter - Asset Image
Flutter is an open-source, cross-platform UI development kit developed by Google. It is gaining popularity these days, as the app made in Flutter can run on various devices regardless of their platform. It is majorly used to develop applications for Android and iOS, as a single app made in Flutter c
2 min read
BLoC Pattern Flutter
In Flutter applications, the Flutter BLoC (Business Logic Component) is used to manage the state. It helps separate business logic from UI. It ensures that the user interface is not strongly liaison with the business logic, making the app more versatile. It is powerful since it allows the creation o
10 min read