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.
Create various files in the specified directory as a skeleton code.
flutter create <DIRECTORY>
Deploy Flutter apps into devices(both android and ios) by creating binary files.
flutter build apk
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.
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.
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>
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.
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>
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>
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
It fetches the necessary packages used in the app if not available and then builds the app.
flutter assemble -o <DIRECTORY>
Running test files
Test commands are used to run test files of Flutter apps.
flutter test [<DIRECTORY|DART_FILE>]
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>
Basic error reporting
The Flutter bug report command captures the basic system info relevant to diagnosing developer-reported bugs.
flutter — bug-report
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.
Getting Flutter version
It gives the version-related information for Flutter and Dart SDKs.
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>
Getting app log
It shows log output (noisy logging), including all shell commands.
flutter run — verbose
The command displays all the devices that are connected for the Flutter development.
flutter devices -d <DEVICE_ID>
The term “devices” refers to the Android emulators, iOS simulators, and real devices.
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>
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>
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
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.