CLI Commands cheat sheet for Flutter

dhiwise

DhiWise

Posted on May 18, 2022

CLI Commands cheat sheet for Flutter

Are you a Flutter developer looking for a CLI command reference? If yes, you must be curious about the different ways you can interact with the Flutter application.

Flutter, a mobile development UI kit managed by Google comes with the handy CLI (Command Line Interface). It lets you do the same tasks that you perform using IDE.

This article will help you get a quick reference to the important CLI commands that are used in almost all Flutter projects.

1. Flutter project commands

Initialization
Create various files in the specified directory as a skeleton code.

flutter create <DIRECTORY>
Enter fullscreen mode Exit fullscreen mode

Flutter build
Deploy Flutter apps into devices(both android and ios) by creating binary files.

flutter build apk
Enter fullscreen mode Exit fullscreen mode

The command has so many options, here are some important arguments that can be used with Flutter build apk command.

    • — debug: build debug version apk.
    • — profile: build a version specialized for performance profiling.
    • — release: Build release version ready for publishing to the app store.
    • — flavor: Build a custom app flavor defined by platform defined by platform-specific build setup.

Flutter clean

Delete Dart-tool folder, android folder, and iOS folder in the build directory. It helps to clear the disk space as even the small apps can consume large disk space that is nearly 200M. So, it’s always a good idea to run Flutter clean for those applications.

flutter clean
Enter fullscreen mode Exit fullscreen mode

Flutter run

The command is used to run the application. However, before running this command make sure you have connected devices to run the app.

flutter run <DART_FILE>
Enter fullscreen mode Exit fullscreen mode

The run command can be used with the following types. By default, the Flutter builds a debug version of an application with hot reload support.

    • — debug: Used to run a debug version.
    • — profile: For versions specialized for performance profiling.
    • — release: To run the release version of an application.
    • — flavor: A custom app flavor defined by platform-specific build setup.

Attaching existing app

While debugging if you lost communication, then you can not use the Hot-Reload or Hot-Restart feature. So, instead of re-building or installing new applications, you can attach existing installed applications.

flutter attach -d <DEVICE_ID>
Enter fullscreen mode Exit fullscreen mode

Flutter install

Hitting the command installs your application into the devices and emulators. But before executing the command, you have to create an app bundle or apk or binary files using the Flutter build command.

flutter install -d <DEVICE_ID>
Enter fullscreen mode Exit fullscreen mode

Adding and removing Flutter packages

Add a package as a direct dependency.

  • flutter pub add

  • Adding package as dev dependency.

  • flutter pub add -d

  • Removing a package

  • flutter pub remove

Get necessary Flutter packages

It fetches the necessary packages used in the app if not available and then builds the app.

flutter assemble -o <DIRECTORY>
Enter fullscreen mode Exit fullscreen mode

2. Test commands in Flutter

Running test files

Test commands are used to run test files of Flutter apps.

flutter test [<DIRECTORY|DART_FILE>]
Enter fullscreen mode Exit fullscreen mode

3. Flutter code analysis

Though your project doesn’t have any errors, it’s essential to analyze your whole project code or specific file using the following command.

flutter analyze -d <DEVICE_ID>
Enter fullscreen mode Exit fullscreen mode

4. Flutter bug/error reporting

Basic error reporting
The Flutter bug report command captures the basic system info relevant to diagnosing developer-reported bugs.

flutter — bug-report
Enter fullscreen mode Exit fullscreen mode

Flutter doctor reporting

The command provides the information about installed tooling required for Flutter development. It lets you know about your Flutter SDK, and whether it is set up correctly and compatible with the platform, IDE, and devices.

flutter doctor
Enter fullscreen mode Exit fullscreen mode

Getting Flutter version

It gives the version-related information for Flutter and Dart SDKs.

flutter version
Enter fullscreen mode Exit fullscreen mode

Getting Flutter channel

The command lists all the Flutter channels available. So, you can see which channel you are using or switch to another channel to access the required features.

flutter channel <CHANNEL_NAME>
Enter fullscreen mode Exit fullscreen mode

Getting app log

It shows log output (noisy logging), including all shell commands.

flutter run — verbose
Enter fullscreen mode Exit fullscreen mode

5.Checking connected devices

The command displays all the devices that are connected for the Flutter development.

flutter devices -d <DEVICE_ID>
Enter fullscreen mode Exit fullscreen mode

The term “devices” refers to the Android emulators, iOS simulators, and real devices.

6. Flutter config

The command is used to configure Flutter functionalities that you require in your project. It enables Flutter desktop and Flutter web support for other platforms which are disabled by default.

flutter config — build-dir=<DIRECTORY>
Enter fullscreen mode Exit fullscreen mode



  1. Flutter format

The command formats the Dart file according to the specified setting in the Flutter SDK. But, if you are using VS-Code or Android Studio with Flutter and the Dart extension, then the Dart file will format automatically.

flutter format <DART_FILE | DIRECTORY>
Enter fullscreen mode Exit fullscreen mode



  1. Flutter help

Use Flutter help if you get stuck anywhere, it is useful, especially for beginners. After hitting the command it shows the list of all Flutter commands.

flutter — help — verbose
Enter fullscreen mode Exit fullscreen mode




Summing up:

All the above commands can be executed through IDE. But it will be helpful if you are using a terminal. Hope you find this Flutter cheat sheet helpful.

Now, speed up your Flutter app development with DhiWise, the world’s first ProCode app development platform that offers full flexibility to build custom applications and generates clean code in a few steps.

Explore more about the amazing platform and sign up to make your project development highly efficient.

💖 💪 🙅 🚩
dhiwise
DhiWise

Posted on May 18, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related