In this post, you will learn about flutter terminal commands and command-line options. Using Flutter command-line interface (CLI), you can perform lots of operations in your project.
Before that make sure you have downloaded Flutter SDK and updated path variable if you are using Windows.
If you haven’t, you can use Flutter Android Studio post to do that.
- Flutter clean – Reduces Project Size by deleting build and .dart_tool directories.
- Flutter build – List Build Commands
- Flutter channel – List Different Flutter Source Code Branches
- Flutter run – Run Flutter Project
- Flutter create – Create New Flutter Project Using Commandline
- Flutter doctor – Diagnoses Flutter system environment.
- Flutter ???
You could run below commands in flutter console too.
This is Flutter console. You can find it in Flutter SDK.
7. Flutter clean – Reduces Project Size by deleting build and .dart_tool directories.
When I created a simple flutter app, it’s size only below 200 kb but after a run in an emulator, Its size largely increases and takes more than 300 MB.
So if you have a low-configuration PC and you are learning flutter by making different apps. That might takes lots of memory in your device.
So just use below command in the root folder of the project.
- Using “flutter clean” command, you can reduce flutter project size. The command just deletes the build directory and some other files.
6.Flutter build – List Build Commands
For publishing your flutter app, you need to make binaries for Android and Ios. The build command by default makes a release flavor of the app.
- It helps to list build formats of flutter
flutter build appbundle - build an appbundle
- Recommended to build appbundle than apk.
flutter build apk
- It builds fat apk.
flutter build apk --split-per-abi
- Above command creates apks based on ABI.
flutter build ios
- Creates binaries for Ios.
5. Flutter channel – List Different Flutter Source Code Branches
Flutter channel means a git branch where we get Flutter source code. It could be used to change different branches such as master, dev, beta, and stable.
Just run “flutter channel” to find out.
- The channel with star symbol is you are currently using.
- Here I am using stable channel and stable is recommended for product development.
Let’s change the channel…
flutter channel [channel_name] – this is syntax, let’s change stable to master.
flutter channel master
- run “flutter upgrade” to ensure you are on the latest build.
4. Flutter run – Run Flutter Project
If you have created your flutter project, then you can run it on any devices or emulators using the run command. While using the run command, it must be called from the root directory of the project. you can use cd command for that purpose.
cd flutter_app flutter run
- If there are no emulators and devices connected, cmd will show “No supported devices connected”.
- The app will get loaded and start running, If single device get connected,.
- Multiple devices get connected, specify one device id with “flutter run -d” command
- Just look at the above image, I just run “flutter run” and I got two devices, emulator and a physical device.
flutter run -d emulator-5554
- Here I use emulator-5554 as device id.
- If you want to run app on all devices, run “flutter run -d all” command.
- By default, the debug version of the app will run on your device. It supports hot reload and fine for testing purposes.
- There are other build flavors you can use like profile, flavor, and release.
- the release version is for when you ready to publish it in play store or Appstore and it is not supported for emulators.
flutter run --release
- If you use above command, you could see that the debug banner is gone.
3.flutter create – Create new flutter project Using Command Line
This command is used to create flutter projects, such as Flutter application, package, plugin, and module.
flutter create [output_directory_name or project_name]
- Creates a Flutter app project
flutter create flutter_app
- Creates a flutter app named “flutter_app”.
- After running above command, necessary files will be created on the specified name.
- project name – It’s recommended to use lowercase with underscores.
- If you run flutter create with existing flutter project name then the project will be recreated and if there are any files is missing, that too recreated again.
- I have deleted main.dart file in the lib folder, now it recreated.
Let’s create a project with our own package name and description, use below code
flutter create --org com.androidride --description "simple example" my_flutter_app
- It creates a package name with “com.androidride”, you can view description in README.md
Let’s check how to create a package using flutter commands.
flutter create -t package flutter_package
- Creates a package named flutter_package.
- You can use -t or –template to specify the flutter project.
Let’s create a plugin project with flutter create command.
flutter create -t plugin flutter_plugin
- It creates plugin project named flutter_plugin.
- By default, swift is used as ios language, Kotlin for Android.
we can change that by using the below command.
flutter create -t plugin -i objc -a java my_flutter_plugin
- Here -i means ios language – objc used, -a means android language.
- You can remove -t plugin, if you are making Flutter application
2.Flutter doctor – Diagnoses Flutter system environment.
This command diagnoses our system and tells us is everything fine or any issues need to treat just like a doctor.
If there are no issues, you are good to go. You don’t need to worry about all issues. For example, you are making a flutter app in VS Code, So you can avoid problems associated with Android Studio.
For example, Flutter plugin not installed in Android Studio like error.
- Here I have one issue because I haven’t connected any devices.
Okay… Let’s know more details by running
flutter doctor -v
- Using the above image, we can understand that flutter doctor -v gave more details about our Flutter development environment and tools.
1. flutter help
Just like the name it helps developers to find other commands and tells us how to use them just like a senior developer who is sitting nearby you. So I think, you don’t need to remember all commands I told above, Just remember this one.
- flutter -h and flutter –help give you the same results.
flutter help -v
- The above command gives a verbose output of flutter help.
flutter help [command]
- Using the above syntax, we can check how other commands work.
flutter help create
- Above command helps us to know more about create command.
Flutter Other Commands
Now I will show you some other commands with fewer details that helped me while I create flutter apps.
- flutter doctor –android-licenses – It helps to accept all android licenses. If it didn’t work, use (your android_sdk directory)\tools\bin\sdkmanager –licenses
- flutter logs – Shows logs generated by flutter apps in emulators and devices.
- flutter analyze – It guides to make better code.
- flutter config – Configures Flutter SDK and other settings.
- flutter config –android-sdk “SDK_PATH” – set Android SDK path.
- flutter config –android-studio-dir “ANDROID_STUDIO_DIRECTORY_LOCATION” – sets Android Studio directory location
- flutter upgrade – upgrade Flutter SDK to latest version
- flutter downgrade – downgrade Flutter SDK to lower version
- flutter pug get – pub is dart’s package manager, this command installs packages. The same function as packages get in Android Studio and Get packages in VS code.
- flutter pub upgrade – upgrade packages to the latest version.
- flutter emulators – shows available emulators.
- flutter devices – shows connected emulators and devices
- flutter screenshot – Takes screenshot from emulator or device
- flutter screenshot -o C:\Users\Admin\Desktop\screenshot.png – Takes screenshot and stores in Desktop. (Windows users)
That’s all for now. Thank you. If you like this post, please share it with your friends and family.