Wednesday, 4 Oct 2023
Hello guys, in this post, I'm going to share my experience installing Flutter on Linux. Flutter itself is a widget/component-based framework and is cross-platform, supporting Android, iOS, and web, using the same codebase. This method should be applicable no matter what distribution you use. In this case, the distribution I'm using is Garuda Linux, which is based on Arch. Okay, without further ado, here is the step-by-step installation of Flutter on Linux.
The first step I took was to install Android Studio, the purpose being to utilize the GUI-based SDK manager that is well-integrated within Android Studio. Because in Garuda Linux, I found it troublesome to maintain the Android SDK through the distribution's package manager (Pacman) to tweak permissions and environment paths. With Android Studio, issues like these should no longer exist.
Installing Android Studio
Okay, moving on after installing Android Studio, let's proceed to accept all the license agreements from Android Studio itself and simultaneously install the Android SDK through Android Studio. After it's done, don't close it yet; open the 'More SDK Manager'. Here, we'll check the emulator and the Android command line tools. Additionally, this step is optional, but we can also install a virtual disk to be run later through the emulator, or alternatively, prepare a native Android device to be used as a test subject through ADB.
open SDK
download flutter
To download the flutter, we can access this page to get a complete guide and get the tarball file of installation, but I will help explain it here. Yup, I don't use a package manager to install Flutter because when I checked, Flutter tends to create a cache in its own folder when running certain commands, and for some reason, it always fails to set permissions for Flutter in its base environment path. So for safety, I just downloaded the tarball file in my home directory like this. Next, I just need to extract it in "/home/username/Flutter".
extract flutter
Next, we need to set up the environment variables so that every installed app can run properly. First, the env ANDROID_HOME, then Flutter as well, and lastly, this one is optional, for Flutter web development, by default, it will look for the base path of Google Chrome as its default browser. But you can use other Chromium-based browsers (for example, in my case, Brave Browser) by setting up the environment variables like this. Next, don't forget to log in, log out, or restart your Linux so that the environment variables are reloaded.
# ........some previous configuration
# taro ini dipaling bawah
export CHROME_EXECUTABLE=/opt/brave-bin/brave
export ANDROID_HOME=/home/$USER/Android/Sdk
export FLUTTER_HOME=/home/$USER/Flutter/bin
export PATH=$PATH:$FLUTTER_HOME
bash_profile.sh
Before moving to the next step, ensure that flutter linceses has been agreed by using this command
flutter doctor --android-licenses
flutter lincenses To check if all settings has been configured we can run this command in the terminal
flutter doctor
flutter doctor
By doing so the terminal will list the dependencies/requirements fulfilled by Flutter. If there are any that appear in red, perhaps something was missed during the setup of Flutter and Android Studio.
This is optional, but I prefer using Visual Studio Code for Flutter development because it is lighter compared to Android Studio, since I don't use XML-based layouts, it's more like working with ReactJS component-based structure. So, I prefer using a regular code editor with ADB/emulator.
In the Visual Studio Code marketplace, there is a cool extension that can be installed to transform VS Code into a Flutter IDE. This way, you can run and debug the main.dart file using the code editor and it will detect the available virtual devices installed as well as the running ADB devices. You can check the extension here
flutter extension
Phew, you made it to the end of this article. With this, Flutter should be ready for you to work on your cool projects out there. Don't forget to share this article if you find it helpful
~ Yazid
Yazid Zaidan Mujadid
Software engineer who loves linux-distro and is a non-smoker (Yeah, get lost cigarettes!), enjoy drinking coffe matcha, can do a little art & design, currently fighting againts the stereotype of bad habits among programmers.
All rights reserved © Yazid Zaidan Mujadid 2023