What is Flutter?
- Flutter is a cross-platform UI framework developed by Google used to build applications for Android, iOS, Web, Windows, macOS, and Linux.
0. (macOS only) You can install using homebrew. If you don’t have it yet, install homebrew with the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then use homebrew to install fvm
brew tap leoafarias/fvm
brew install fvm
You can also install fvm on other platforms If you’re interested, check the documentation directly
1. Download Flutter SDK from the official site or install using fvm
introduced in the previous step
a. (mac/windows) Download the officially provided version from the link above
b. Or download using fvm
fvm install stable # Install the latest stable version
Then set the default Flutter version
globally
fvm global stable
2. Set up Flutter in your environment variables
(windows
) Set the following path in environment variables (if manually downloaded, replace with the corresponding bin path)
$HOME/fvm/default/bin
(macos
) Set in terminal configuration,
for example in the common .zshrc
:
open ~/.zshrc
Then add the following to .zshrc
export PATH=$PATH:"$HOME/fvm/default/bin"
3. Use flutter doctor
to check what’s missing in your current environment and install what’s needed
- If you’re building for
android, macos, ios
, you’ll need to download Android Studio and Xcode -
Even with everything installed, you might encounter errors due to incomplete installation of Android Tools or iOS CocoapPods
- In my case, I encountered three issues
cmdline-tools
not found
- Use
sdkManager
inAndroid tool
to install. If you know the path to sdkManager or have it set in environment variables, installcmdline-tools
directly with the command$ANDROID_SDK_ROOT/tools/bin/sdkmanager --install "cmdline-tools;latest"
- You might encounter Java version compatibility issues. If so, switch your local Java version. In my case, reverting to Java 8 fixed it
- Use
-
CocoaPods
compatibility issue:
- You can install the latest version using the
sudo gem install cocoapods
command
- You can install the latest version using the
- Haven’t
agreed
to Android licenses:
You canagree
with the following commandflutter doctor --android-licenses
Run flutter doctor again
to see if you were successful. If successful, you’ll be able to develop or compile Flutter
Running Directly on Target Device
- Navigate to the
root directory
of your Flutter project
- When you run directly, any missing resources or tools will be downloaded, then you’ll be asked to
select a target platform
to run onflutter run
Building a dmg file for macOS
-
Navigate to the
root directory
of your Flutter project
- Make sure compilation for macOS is enabled
flutter config --enable-macos-desktop
- Build for a specific platform. The following example is for macOS
flutter build macos
- After the build is complete, an
xxx.app
is generated
- After the build is complete, an
-
The xxx.app generated above is still just an application. If you need a
.dmg
, you need to package it further- You’ll need to use the
create-dmg
plugin, so install it withnpm
npm install -g create-dmg
- Package the xxx.app you just built:
--dmg-title
: You can set the name of the installation package on disk
create-dmg build/macos/Build/Products/Release/xxx.app --dmg-title="Application Name" --overwrite
- You’ll need to use the
- I’ve written about this in another article, please refer to it