id
stringlengths 14
17
| text
stringlengths 23
1.11k
| source
stringlengths 35
114
|
---|---|---|
65dd0840706f-5 | Configuring Android app support
Note:
Flutter relies on a full installation of Android Studio to supply
its Android platform dependencies. However, you can write your
Flutter apps in a number of editors; a later step discusses that.
Install Android Studio
Download and install Android Studio.
Start Android Studio, and go through the ‘Android Studio Setup Wizard’.
This installs the latest Android SDK, platform tools and build tooling
that are required by Flutter when developing for Android.
From the welcome dialog, choose More Actions -> SDK Manager.
From the SDK Tools tab, select
Android SDK Command-line Tools (latest)
to install additional necessary tooling.
Accept Android licenses.
flutter doctor
-android-licenses
Deploy to your Chromebook
To deploy apps directly to your Chromebook, you need to do the following: | https://docs.flutter.dev/get-started/install/chromeos/index.html |
65dd0840706f-6 | To deploy apps directly to your Chromebook, you need to do the following:
Enable ADB in Settings. Note that this requires you to reboot your
device once.
In the Terminal, run flutter devices. If prompted, authorize access to
the Android container. Verify that flutter devices lists your ChromeOS
device as a recognized device.
Set up your Android device
To prepare to run and test your Flutter app on an attached device,
you need an Android device running Android 4.1 (API level 16) or higher.
Enable Developer options and USB debugging on your device.
Detailed instructions are available in the
Android documentation.
Using a USB cable, plug your phone into your computer. On your Chromebook,
you may see a notification for “USB device detected”. Click on “Connect
to Linux” If prompted on your Android device, authorize your computer
to access your device. | https://docs.flutter.dev/get-started/install/chromeos/index.html |
65dd0840706f-7 | In the terminal, run the flutter devices command to verify that
Flutter recognizes your connected Android device. By default,
Flutter uses the version of the Android SDK where your adb
tool is based. If you want Flutter to use a different installation
of the Android SDK, you must set the ANDROID_SDK_ROOT environment
variable to that installation directory.
Next step
Set up your preferred editor.
Set up an editor | https://docs.flutter.dev/get-started/install/chromeos/index.html |
f462d2e94ee2-0 | Set up an editor
Install
Get started
Install
Select the operating system on which you are installing Flutter:
Windows
macOS
Linux
ChromeOS
Important:
If you’re in China, first read Using Flutter in China.
Set up an editor | https://docs.flutter.dev/get-started/install/index.html |
b270854a6277-0 | Set up an editor
Linux install
Get started
Install
Linux
System requirements
Get the Flutter SDK
Install Flutter using snapd
Install Flutter manually
Run flutter doctor
Update your path
Update path directly
Android setup
Install Android Studio
Set up your Android device
Set up the Android emulator
Agree to Android Licenses
Linux setup
Additional Linux requirements
Next step
System requirements
To install and run Flutter,
your development environment must meet these minimum requirements:
Operating Systems: Linux (64-bit)
Disk Space: 600 MB (does not include disk space for IDE/tools). | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-1 | Disk Space: 600 MB (does not include disk space for IDE/tools).
Tools: Flutter depends on these command-line tools being available
in your environment.
bash
curl
file
git 2.x
mkdir
rm
unzip
which
xz-utils
zip
Shared libraries: Flutter test command depends on this library
being available in your environment.
libGLU.so.1 - provided by mesa packages such as libglu1-mesa on
Ubuntu/Debian and mesa-libGLU on Fedora.
Get the Flutter SDK
On Linux, you have two ways you can install Flutter.
Install Flutter using snapd
The easiest way to install Flutter on Linux is by
using snapd. For more information,
see Installing snapd. | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-2 | Once you have snapd, you can
install Flutter using the Snap Store,
or at the command line:
sudo snap
install flutter
-classic
Note:
Once you install the snap,
use the following command to display your Flutter SDK path:
flutter sdk-path
Install Flutter manually
If you don’t have snapd, or can’t use it, you can
install Flutter using the following steps.
Download the following installation bundle to get the latest
stable release of the Flutter SDK:
(loading…)
For other release channels, and older builds,
see the SDK releases page.
Extract the file in the desired location, for example:
$ cd ~/development
$ tar xf ~/Downloads/flutter_linux_vX.X.X-stable.tar.xz | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-3 | If you don’t want to install a fixed version of the installation bundle,
you can skip steps 1 and 2.
Instead, get the source code from the Flutter repo
on GitHub with the following command:
$ git clone https://github.com/flutter/flutter.git
You can also change branches or tags as needed.
For example, to get just the stable version:
$ git clone https://github.com/flutter/flutter.git -b stable
Add the flutter tool to your path:
$ export PATH="$PATH:`pwd`/flutter/bin"
This command sets your PATH variable for the
current terminal window only.
To permanently add Flutter to your path, see
Update your path.
Optionally, pre-download development binaries: | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-4 | Optionally, pre-download development binaries:
The flutter tool downloads platform-specific development binaries as
needed. For scenarios where pre-downloading these artifacts is preferable
(for example, in hermetic build environments,
or with intermittent network availability), iOS
and Android binaries can be downloaded ahead of time by running:
$ flutter precache
For additional download options, see flutter help precache.
You are now ready to run Flutter commands!
Note:
To update an existing version of Flutter, see
Upgrading Flutter.
Run flutter doctor
Run the following command to see if there are any dependencies you need to
install to complete the setup (for verbose output, add the -v flag):
flutter doctor | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-5 | flutter doctor
This command checks your environment and displays a report to the terminal
window. The Dart SDK is bundled with Flutter; it is not necessary to install
Dart separately. Check the output carefully for other software you might
need to install or further tasks to perform (shown in bold text).
For example:
The following sections describe how to perform these tasks and finish the setup
process.
Once you have installed any missing dependencies, run the flutter doctor
command again to verify that you’ve set everything up correctly.
Warning:
The Flutter tool may occasionally download resources from Google servers.
By downloading or using the Flutter SDK you agree to the Google Terms of Service. | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-6 | For example, when installed from GitHub (as opposed to from a prepackaged archive),
the Flutter tool will download the Dart SDK from Google servers immediately when
first run, as it is used to execute the flutter tool itself. This will also
occur when Flutter is upgraded (e.g. by running the flutter upgrade command).
The flutter tool uses Google Analytics to report feature usage
statistics and send crash reports. This data is used to help improve Flutter
tools over time.
Flutter tool analytics are not sent on the very first run. To disable
reporting, run flutter config --no-analytics. To display the current
setting, use flutter config. If you opt out of analytics, an opt-out
event is sent, and then no further information is sent by the
Flutter tool.
Dart tools may also send usage metrics and crash reports to Google.
To control the submission of these metrics, use the following options on the
dart tool: | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-7 | --enable-analytics: Enables anonymous analytics.
--disable-analytics: Disables anonymous analytics.
The Google Privacy Policy describes how data is handled by these services.
Update your path
You can update your PATH variable for the current session at
the command line, as shown in Get the Flutter SDK.
You’ll probably want to update this variable permanently,
so you can run flutter commands in any terminal session.
The steps for modifying this variable permanently for
all terminal sessions are machine-specific.
Typically you add a line to a file that is executed
whenever you open a new window. For example:
Determine the path of your clone of the Flutter SDK.
You need this in Step 3.
Open (or create) the rc file for your shell.
For example, Linux uses the Bash shell by default,
so edit $HOME/.bashrc.
If you are using a different shell, the file path
and filename will be different on your machine. | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-8 | Add the following line and change
[PATH_OF_FLUTTER_GIT_DIRECTORY] to be
the path of your clone of the Flutter git repo:
$ export PATH="$PATH:[PATH_OF_FLUTTER_GIT_DIRECTORY]/bin"
Run source $HOME/.<rc file>
to refresh the current window,
or open a new terminal window to
automatically source the file.
Verify that the flutter/bin directory
is now in your PATH by running:
$ echo $PATH
Verify that the flutter command is available by running:
$ which flutter
which flutter dart
/path-to-flutter-sdk/bin/flutter
/usr/local/bin/dart
which flutter dart
/path-to-flutter-sdk/bin/flutter
/path-to-flutter-sdk/bin/dart | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-9 | To learn more about the dart command, run dart -h
from the command line, or see the dart tool page.
Update path directly
In some cases, your distribution may not permanently acquire
the path when using the above directions. When this occurs,
you can change the environment variables file directly.
These instructions require administrator privileges:
Determine the path of your clone of the Flutter SDK.
Locate the etc directory at the root of the system,
and open the profile file with root privileges.
$ sudo nano /etc/profile
Update the PATH string with the location of your
Flutter SDK directory.
if [ "`id -u`" -eq 0 ]; then
PATH="..."
else
PATH="/usr/local/bin:...:[PATH_OF_FLUTTER_GIT_DIRECTORY]/bin"
fi
export PATH
End the current session or reboot your system. | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-10 | End the current session or reboot your system.
Once you start a new session, verify that the
flutter command is available by running:
$ which flutter
For more details on setting the path in Bash,
see this StackExchange question.
For information on setting the path in Z shell,
see this StackOverflow question.
Android setup
Note:
Flutter relies on a full installation of Android Studio to supply
its Android platform dependencies. However, you can write your
Flutter apps in a number of editors; a later step discusses that.
Install Android Studio
Download and install Android Studio.
Start Android Studio, and go through the ‘Android Studio Setup Wizard’.
This installs the latest Android SDK, Android SDK Command-line Tools,
and Android SDK Build-Tools, which are required by Flutter
when developing for Android. | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-11 | Run flutter doctor to confirm that Flutter has located
your installation of Android Studio. If Flutter cannot locate it,
run flutter config --android-studio-dir=<directory> to set the
directory that Android Studio is installed to.
Set up your Android device
To prepare to run and test your Flutter app on an Android device,
you need an Android device running Android 4.1 (API level 16) or higher.
Enable Developer options and USB debugging on your device.
Detailed instructions are available in the
Android documentation.
Windows-only: Install the Google USB
Driver.
Using a USB cable, plug your phone into your computer. If prompted on your
device, authorize your computer to access your device. | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-12 | In the terminal, run the flutter devices command to verify that
Flutter recognizes your connected Android device. By default,
Flutter uses the version of the Android SDK where your adb
tool is based. If you want Flutter to use a different installation
of the Android SDK, you must set the ANDROID_SDK_ROOT environment
variable to that installation directory.
Set up the Android emulator
To prepare to run and test your Flutter app on the Android emulator,
follow these steps:
Enable
VM acceleration
on your machine.
Launch Android Studio, click the AVD Manager
icon, and select Create Virtual Device…
In older versions of Android Studio, you should instead
launch Android Studio > Tools > Android > AVD Manager and select
Create Virtual Device…. (The Android submenu is only present
when inside an Android project.)
If you do not have a project open, you can choose
Configure > AVD Manager and select Create Virtual Device…
Choose a device definition and select Next. | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-13 | Choose a device definition and select Next.
Select one or more system images for the Android versions you want
to emulate, and select Next.
An x86 or x86_64 image is recommended.
Under Emulated Performance, select Hardware - GLES 2.0 to enable
hardware
acceleration.
Verify the AVD configuration is correct, and select Finish.
For details on the above steps, see Managing
AVDs.
In Android Virtual Device Manager, click Run in the toolbar.
The emulator starts up and displays the default canvas for your
selected OS version and device.
Agree to Android Licenses
Before you can use Flutter, you must agree to the
licenses of the Android SDK platform. This step should be done after
you have installed the tools listed above.
Make sure that you have a version of Java 11 installed and that your
JAVA_HOME environment variable is set to the JDK’s folder. | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-14 | Android Studio versions 2.2 and higher come with a JDK, so this should
already be done.
Open an elevated console window and run the following command to begin
signing licenses.
$ flutter doctor --android-licenses
Review the terms of each license carefully before agreeing to them.
Once you are done agreeing with licenses, run flutter doctor again
to confirm that you are ready to use Flutter.
Linux setup
Additional Linux requirements
For Linux desktop development,
you need the following in addition to the Flutter SDK:
Clang
CMake
GTK development headers
Ninja build
pkg-config
liblzma-dev This might be necessary
Run the following command
sudo apt-get | https://docs.flutter.dev/get-started/install/linux/index.html |
b270854a6277-15 | Run the following command
sudo apt-get
install clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev
Next step
Set up your preferred editor.
Set up an editor | https://docs.flutter.dev/get-started/install/linux/index.html |
010bf8e5320d-0 | Set up an editor
macOS install
Get started
Install
macOS
System requirements
Get the Flutter SDK
Run flutter doctor
Downloading straight from GitHub instead of using an archive
Update your path
Platform setup
iOS setup
Install Xcode
Set up the iOS simulator
Create and run a simple Flutter app
Deploy to iOS devices
Android setup
Install Android Studio
Set up your Android device
Set up the Android emulator
Agree to Android Licenses
macOS setup
Additional macOS requirements
Next step
System requirements
To install and run Flutter,
your development environment must meet these minimum requirements:
Operating Systems: macOS, version 10.14 (Mojave) or later. | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-1 | Disk Space: 2.8 GB (does not include disk space for IDE/tools).
Tools: Flutter uses git for installation and upgrade. We recommend
installing Xcode, which includes git, but you can also
install git separately.
Important:
If you’re installing on an Apple Silicon Mac, you must have the Rosetta
translation environment available for some ancillary tools.
You can install this manually by running:
sudo softwareupdate
-install-rosetta
-agree-to-license
Get the Flutter SDK
Download the following installation bundle to get the latest
stable release of the Flutter SDK:
Intel
Apple Silicon
(loading…)
(loading…)
For other release channels, and older builds,
see the SDK releases page. | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-2 | For other release channels, and older builds,
see the SDK releases page.
Tip:
To determine whether your Mac uses an Apple silicon processor, refer to Mac computers with Apple silicon on apple.com
Extract the file in the desired location, for example:
$ cd ~/development
$ unzip ~/Downloads/flutter_macos_vX.X.X-stable.zip
Add the flutter tool to your path:
$ export PATH="$PATH:`pwd`/flutter/bin"
This command sets your PATH variable for the
current terminal window only.
To permanently add Flutter to your path, see
Update your path.
You are now ready to run Flutter commands!
Note:
To update an existing version of Flutter, see
Upgrading Flutter.
Run flutter doctor | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-3 | Run flutter doctor
Run the following command to see if there are any dependencies you need to
install to complete the setup (for verbose output, add the -v flag):
flutter doctor
This command checks your environment and displays a report to the terminal
window. The Dart SDK is bundled with Flutter; it is not necessary to install
Dart separately. Check the output carefully for other software you might
need to install or further tasks to perform (shown in bold text).
For example:
The following sections describe how to perform these tasks and finish the setup
process.
Once you have installed any missing dependencies, run the flutter doctor
command again to verify that you’ve set everything up correctly.
Downloading straight from GitHub instead of using an archive
This is only suggested for advanced use cases.
You can also use git directly instead of downloading the prepared archive. For example,
to download the stable branch:
git clone https://github.com/flutter/flutter.git | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-4 | git clone https://github.com/flutter/flutter.git
b stable
Update your path, and run flutter doctor. That will let you know if there are
other dependencies you need to install to use Flutter (e.g. the Android SDK).
If you did not use the archive, Flutter will download necessary development binaries as they
are needed (if you used the archive, they are included in the download). You may wish to
pre-download these development binaries (for example, you may wish to do this when setting
up hermetic build environments, or if you only have intermittent network availability). To
do so, run the following command:
flutter precache
For additional download options, see flutter help precache.
Warning:
The Flutter tool may occasionally download resources from Google servers.
By downloading or using the Flutter SDK you agree to the Google Terms of Service. | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-5 | For example, when installed from GitHub (as opposed to from a prepackaged archive),
the Flutter tool will download the Dart SDK from Google servers immediately when
first run, as it is used to execute the flutter tool itself. This will also
occur when Flutter is upgraded (e.g. by running the flutter upgrade command).
The flutter tool uses Google Analytics to report feature usage
statistics and send crash reports. This data is used to help improve Flutter
tools over time.
Flutter tool analytics are not sent on the very first run. To disable
reporting, run flutter config --no-analytics. To display the current
setting, use flutter config. If you opt out of analytics, an opt-out
event is sent, and then no further information is sent by the
Flutter tool.
Dart tools may also send usage metrics and crash reports to Google.
To control the submission of these metrics, use the following options on the
dart tool: | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-6 | --enable-analytics: Enables anonymous analytics.
--disable-analytics: Disables anonymous analytics.
The Google Privacy Policy describes how data is handled by these services.
Update your path
You can update your PATH variable for the current session at
the command line, as shown in Get the Flutter SDK.
You’ll probably want to update this variable permanently,
so you can run flutter commands in any terminal session.
The steps for modifying this variable permanently for
all terminal sessions are machine-specific.
Typically you add a line to a file that is executed
whenever you open a new window. For example:
Determine the path of your clone of the Flutter SDK.
You need this in Step 3. | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-7 | Open (or create) the rc file for your shell.
Typing echo $SHELL in your Terminal tells you
which shell you’re using.
If you’re using Bash,
edit $HOME/.bash_profile or $HOME/.bashrc.
If you’re using Z shell, edit $HOME/.zshrc.
If you’re using a different shell, the file path
and filename will be different on your machine.
Add the following line and change
[PATH_OF_FLUTTER_GIT_DIRECTORY] to be
the path of your clone of the Flutter git repo:
$ export PATH="$PATH:[PATH_OF_FLUTTER_GIT_DIRECTORY]/bin"
Run source $HOME/.<rc file>
to refresh the current window,
or open a new terminal window to
automatically source the file.
Verify that the flutter/bin directory
is now in your PATH by running: | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-8 | Verify that the flutter/bin directory
is now in your PATH by running:
$ echo $PATH
Verify that the flutter command is available by running:
$ which flutter
Platform setup
macOS supports developing Flutter apps for iOS, Android, macOS itself
and the web. Complete at least one of the platform setup steps now,
to be able to build and run your first Flutter app.
iOS setup
Install Xcode
To develop Flutter apps for iOS, you need a Mac with Xcode installed.
Install the latest stable version of Xcode
(using web download or the Mac App Store).
Configure the Xcode command-line tools to use the
newly-installed version of Xcode by
running the following from the command line:
$ sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
$ sudo xcodebuild -runFirstLaunch | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-9 | This is the correct path for most cases,
when you want to use the latest version of Xcode.
If you need to use a different version,
specify that path instead.
Make sure the Xcode license agreement is signed by
either opening Xcode once and confirming or running
sudo xcodebuild -license from the command line.
Versions older than the latest stable version may still work,
but are not recommended for Flutter development.
With Xcode, you’ll be able to run Flutter apps on
an iOS device or on the simulator.
Set up the iOS simulator
To prepare to run and test your Flutter app on the iOS simulator,
follow these steps:
On your Mac, find the Simulator via Spotlight or
by using the following command:
$ open -a Simulator | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-10 | $ open -a Simulator
Make sure your simulator is using a 64-bit device
(iPhone 5s or later). You can check the device by viewing the settings in
the simulator’s Hardware > Device or File > Open Simulator menus.
Depending on your development machine’s screen size,
simulated high-screen-density iOS devices
might overflow your screen. Grab the corner of the
simulator and drag it to change the scale. You can also
use the Window > Physical Size or Window > Pixel Accurate
options if your computer’s resolution is high enough.
Create and run a simple Flutter app
To create your first Flutter app and test your setup,
follow these steps:
Create a new Flutter app by running the following from the
command line:
$ flutter create my_app
A my_app directory is created, containing Flutter’s starter app.
Enter this directory: | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-11 | $ cd my_app
To launch the app in the Simulator,
ensure that the Simulator is running and enter:
$ flutter run
Deploy to iOS devices
To deploy your Flutter app to a physical iPhone or iPad
you’ll need to set up physical device deployment in Xcode
and an Apple Developer account. If your app is using Flutter plugins,
you will also need the third-party CocoaPods dependency manager.
The first time you use an attached physical device for iOS
development, you need to trust both your Mac and the
Development Certificate on that device.
On iOS 16 and higher you must also enable Developer Mode.
Select Trust in the dialog prompt when
first connecting the iOS device to your Mac. | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-12 | Then, go to the Settings app on the iOS device,
select General > Device Management
and trust your Certificate.
For first time users, you might need to select
General > Profiles > Device Management instead.
On iOS 16 and higher, navigate back to the top level
of the Settings app, select Privacy & Security > Developer Mode,
and toggle Developer Mode on.
You can skip this step if your apps do not depend on
Flutter plugins with native iOS code.
Install and set up CocoaPods by running the following commands:
$ sudo gem install cocoapods
Note:
The default version of Ruby requires sudo to install the CocoaPods gem.
If you are using a Ruby Version manager, you might need to run without sudo.
Additionally, if you are installing on an Apple Silicon Mac,
run the command:
$ sudo gem uninstall ffi && sudo gem install ffi -- --enable-libffi-alloc | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-13 | Follow the Xcode signing flow to provision your project:
Open the default Xcode workspace in your project by
running open ios/Runner.xcworkspace in a terminal
window from your Flutter project directory.
Select the device you intend to deploy to in the device
drop-down menu next to the run button.
Select the Runner project in the left navigation panel.
In the Runner target settings page,
make sure your Development Team is selected
under Signing & Capabilities > Team.
When you select a team,
Xcode creates and downloads a Development Certificate,
registers your device with your account,
and creates and downloads a provisioning profile (if needed). | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-14 | To start your first iOS development project,
you might need to sign into
Xcode with your Apple ID.
Development and testing is supported for any Apple ID.
Enrolling in the Apple Developer Program is required to
distribute your app to the App Store.
For details about membership types,
see Choosing a Membership.
If automatic signing fails in Xcode, verify that the project’s
General > Identity > Bundle Identifier value is unique.
Start your app by running flutter run
or clicking the Run button in Xcode.
Android setup
Note:
Flutter relies on a full installation of Android Studio to supply
its Android platform dependencies. However, you can write your
Flutter apps in a number of editors; a later step discusses that.
Install Android Studio
Download and install Android Studio. | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-15 | Install Android Studio
Download and install Android Studio.
Start Android Studio, and go through the ‘Android Studio Setup Wizard’.
This installs the latest Android SDK, Android SDK Command-line Tools,
and Android SDK Build-Tools, which are required by Flutter
when developing for Android.
Run flutter doctor to confirm that Flutter has located
your installation of Android Studio. If Flutter cannot locate it,
run flutter config --android-studio-dir=<directory> to set the
directory that Android Studio is installed to.
Set up your Android device
To prepare to run and test your Flutter app on an Android device,
you need an Android device running Android 4.1 (API level 16) or higher.
Enable Developer options and USB debugging on your device.
Detailed instructions are available in the
Android documentation.
Windows-only: Install the Google USB
Driver. | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-16 | Windows-only: Install the Google USB
Driver.
Using a USB cable, plug your phone into your computer. If prompted on your
device, authorize your computer to access your device.
In the terminal, run the flutter devices command to verify that
Flutter recognizes your connected Android device. By default,
Flutter uses the version of the Android SDK where your adb
tool is based. If you want Flutter to use a different installation
of the Android SDK, you must set the ANDROID_SDK_ROOT environment
variable to that installation directory.
Set up the Android emulator
To prepare to run and test your Flutter app on the Android emulator,
follow these steps:
Enable
VM acceleration
on your machine. | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-17 | Enable
VM acceleration
on your machine.
Launch Android Studio, click the AVD Manager
icon, and select Create Virtual Device…
In older versions of Android Studio, you should instead
launch Android Studio > Tools > Android > AVD Manager and select
Create Virtual Device…. (The Android submenu is only present
when inside an Android project.)
If you do not have a project open, you can choose
Configure > AVD Manager and select Create Virtual Device…
Choose a device definition and select Next.
Select one or more system images for the Android versions you want
to emulate, and select Next.
An x86 or x86_64 image is recommended.
Under Emulated Performance, select Hardware - GLES 2.0 to enable
hardware
acceleration.
Verify the AVD configuration is correct, and select Finish.
For details on the above steps, see Managing
AVDs. | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-18 | For details on the above steps, see Managing
AVDs.
In Android Virtual Device Manager, click Run in the toolbar.
The emulator starts up and displays the default canvas for your
selected OS version and device.
Agree to Android Licenses
Before you can use Flutter, you must agree to the
licenses of the Android SDK platform. This step should be done after
you have installed the tools listed above.
Make sure that you have a version of Java 11 installed and that your
JAVA_HOME environment variable is set to the JDK’s folder.
Android Studio versions 2.2 and higher come with a JDK, so this should
already be done.
Open an elevated console window and run the following command to begin
signing licenses.
$ flutter doctor --android-licenses
Review the terms of each license carefully before agreeing to them. | https://docs.flutter.dev/get-started/install/macos/index.html |
010bf8e5320d-19 | Review the terms of each license carefully before agreeing to them.
Once you are done agreeing with licenses, run flutter doctor again
to confirm that you are ready to use Flutter.
macOS setup
Additional macOS requirements
For macOS desktop development,
you need the following in addition to the Flutter SDK:
Xcode
CocoaPods if you use plugins
Next step
Set up your preferred editor.
Set up an editor | https://docs.flutter.dev/get-started/install/macos/index.html |
a8bcd7a33481-0 | Set up an editor
Windows install
Get started
Install
Windows
System requirements
Get the Flutter SDK
Update your path
Run flutter doctor
Android setup
Install Android Studio
Set up your Android device
Set up the Android emulator
Agree to Android Licenses
Windows setup
Additional Windows requirements
Next step
System requirements
To install and run Flutter,
your development environment must meet these minimum requirements:
Operating Systems: Windows 10 or later (64-bit), x86-64 based.
Disk Space: 1.64 GB (does not include disk space for IDE/tools). | https://docs.flutter.dev/get-started/install/windows/index.html |
a8bcd7a33481-1 | Tools: Flutter depends on these tools being available in your environment.
Windows PowerShell 5.0 or newer (this is pre-installed with Windows 10)
Git for Windows 2.x, with the
Use Git from the Windows Command Prompt option.
If Git for Windows is already installed,
make sure you can run git commands from the
command prompt or PowerShell.
Get the Flutter SDK
Download the following installation bundle to get the latest
stable release of the Flutter SDK:
(loading…)
For other release channels, and older builds,
see the SDK releases page.
Extract the zip file and place the contained flutter
in the desired installation location for the Flutter SDK
(for example, C:\src\flutter).
Warning:
Do not install Flutter to a path that contains special
characters or spaces. | https://docs.flutter.dev/get-started/install/windows/index.html |
a8bcd7a33481-2 | Warning:
Do not install Flutter in a directory like
C:\Program Files\ that requires elevated privileges.
If you don’t want to install a fixed version of the installation
bundle, you can skip steps 1 and 2. Instead, get the source code
from the Flutter repo on
GitHub, and change branches or tags as needed. For example:
C:\src>git
clone
https://github.com/flutter/flutter.git
b
stable
You are now ready to run Flutter commands in the Flutter Console.
Update your path
If you wish to run Flutter commands in the regular Windows console,
take these steps to add Flutter to the PATH environment variable:
From the Start search bar, enter ‘env’
and select Edit environment variables for your account. | https://docs.flutter.dev/get-started/install/windows/index.html |
a8bcd7a33481-3 | Under User variables check if there is an entry called Path:
If the entry exists, append the full path to flutter\bin using
; as a separator from existing values.
If the entry doesn’t exist,
create a new user variable named Path with
the full path to flutter\bin as its value.
You have to close and reopen any existing console windows
for these changes to take effect.
C:\>where flutter dart
C:\path-to-flutter-sdk\bin\flutter
C:\path-to-flutter-sdk\bin\flutter.bat
C:\path-to-dart-sdk\bin\dart.exe :: this should go after `C:\path-to-flutter-sdk\bin\` commands
C:\path-to-flutter-sdk\bin\dart
C:\path-to-flutter-sdk\bin\dart.bat
C:\>where flutter dart | https://docs.flutter.dev/get-started/install/windows/index.html |
a8bcd7a33481-4 | C:\>where flutter dart
C:\dev\src\flutter\bin\flutter
C:\dev\src\flutter\bin\flutter.bat
C:\dev\src\flutter\bin\dart
C:\dev\src\flutter\bin\dart.bat
C:\dev\src\dart-sdk\bin\dart.exe
However, if you are using PowerShell, in it where is
an alias of Where-Object command, so you need to use where.exe instead.
PS C:\>
where.exe flutter dart
To learn more about the dart command, run dart -h
from the command line, or see the dart tool page.
Run flutter doctor
From a console window that has the Flutter directory in the
path (see above), run the following command to see if there
are any platform dependencies you need to complete the setup:
C:\src\flutter>flutter
doctor | https://docs.flutter.dev/get-started/install/windows/index.html |
a8bcd7a33481-5 | C:\src\flutter>flutter
doctor
This command checks your environment and displays a report of the status
of your Flutter installation. Check the output carefully for other
software you might need to install or further tasks to perform
(shown in bold text).
For example:
The following sections describe how to perform these tasks and
finish the setup process. Once you have installed any missing
dependencies, you can run the flutter doctor command again to
verify that you’ve set everything up correctly.
Note:
If flutter doctor returns that either the Flutter plugin
or Dart plugin of Android Studio are not installed, move
on to Set up an editor to resolve this issue.
Warning:
The Flutter tool may occasionally download resources from Google servers.
By downloading or using the Flutter SDK you agree to the Google Terms of Service. | https://docs.flutter.dev/get-started/install/windows/index.html |
a8bcd7a33481-6 | For example, when installed from GitHub (as opposed to from a prepackaged archive),
the Flutter tool will download the Dart SDK from Google servers immediately when
first run, as it is used to execute the flutter tool itself. This will also
occur when Flutter is upgraded (e.g. by running the flutter upgrade command).
The flutter tool uses Google Analytics to report feature usage
statistics and send crash reports. This data is used to help improve Flutter
tools over time.
Flutter tool analytics are not sent on the very first run. To disable
reporting, run flutter config --no-analytics. To display the current
setting, use flutter config. If you opt out of analytics, an opt-out
event is sent, and then no further information is sent by the
Flutter tool.
Dart tools may also send usage metrics and crash reports to Google.
To control the submission of these metrics, use the following options on the
dart tool: | https://docs.flutter.dev/get-started/install/windows/index.html |
a8bcd7a33481-7 | --enable-analytics: Enables anonymous analytics.
--disable-analytics: Disables anonymous analytics.
The Google Privacy Policy describes how data is handled by these services.
Android setup
Note:
Flutter relies on a full installation of Android Studio to supply
its Android platform dependencies. However, you can write your
Flutter apps in a number of editors; a later step discusses that.
Install Android Studio
Download and install Android Studio.
Start Android Studio, and go through the ‘Android Studio Setup Wizard’.
This installs the latest Android SDK, Android SDK Command-line Tools,
and Android SDK Build-Tools, which are required by Flutter
when developing for Android.
Run flutter doctor to confirm that Flutter has located
your installation of Android Studio. If Flutter cannot locate it,
run flutter config --android-studio-dir=<directory> to set the
directory that Android Studio is installed to. | https://docs.flutter.dev/get-started/install/windows/index.html |
a8bcd7a33481-8 | Set up your Android device
To prepare to run and test your Flutter app on an Android device,
you need an Android device running Android 4.1 (API level 16) or higher.
Enable Developer options and USB debugging on your device.
Detailed instructions are available in the
Android documentation.
Windows-only: Install the Google USB
Driver.
Using a USB cable, plug your phone into your computer. If prompted on your
device, authorize your computer to access your device.
In the terminal, run the flutter devices command to verify that
Flutter recognizes your connected Android device. By default,
Flutter uses the version of the Android SDK where your adb
tool is based. If you want Flutter to use a different installation
of the Android SDK, you must set the ANDROID_SDK_ROOT environment
variable to that installation directory.
Set up the Android emulator
To prepare to run and test your Flutter app on the Android emulator,
follow these steps: | https://docs.flutter.dev/get-started/install/windows/index.html |
a8bcd7a33481-9 | Enable
VM acceleration
on your machine.
Launch Android Studio, click the AVD Manager
icon, and select Create Virtual Device…
In older versions of Android Studio, you should instead
launch Android Studio > Tools > Android > AVD Manager and select
Create Virtual Device…. (The Android submenu is only present
when inside an Android project.)
If you do not have a project open, you can choose
Configure > AVD Manager and select Create Virtual Device…
Choose a device definition and select Next.
Select one or more system images for the Android versions you want
to emulate, and select Next.
An x86 or x86_64 image is recommended.
Under Emulated Performance, select Hardware - GLES 2.0 to enable
hardware
acceleration.
Verify the AVD configuration is correct, and select Finish.
For details on the above steps, see Managing
AVDs. | https://docs.flutter.dev/get-started/install/windows/index.html |
a8bcd7a33481-10 | For details on the above steps, see Managing
AVDs.
In Android Virtual Device Manager, click Run in the toolbar.
The emulator starts up and displays the default canvas for your
selected OS version and device.
Agree to Android Licenses
Before you can use Flutter, you must agree to the
licenses of the Android SDK platform. This step should be done after
you have installed the tools listed above.
Make sure that you have a version of Java 11 installed and that your
JAVA_HOME environment variable is set to the JDK’s folder.
Android Studio versions 2.2 and higher come with a JDK, so this should
already be done.
Open an elevated console window and run the following command to begin
signing licenses.
$ flutter doctor --android-licenses
Review the terms of each license carefully before agreeing to them. | https://docs.flutter.dev/get-started/install/windows/index.html |
a8bcd7a33481-11 | Review the terms of each license carefully before agreeing to them.
Once you are done agreeing with licenses, run flutter doctor again
to confirm that you are ready to use Flutter.
Windows setup
Additional Windows requirements
For Windows desktop development,
you need the following in addition to the Flutter SDK:
Visual Studio 2022 or Visual Studio Build Tools 2022
When installing Visual Studio or only the Build Tools,
you need the “Desktop development with C++” workload installed
for building windows, including all of its default components.
Note:
Visual Studio is different than Visual Studio Code.
For more information, see Building Windows apps.
Next step
Set up your preferred editor.
Set up an editor | https://docs.flutter.dev/get-started/install/windows/index.html |
5017ead5ec61-0 | Write your first Flutter app
Learn more
Get started
Learn more
Flutter basics
Apply your existing knowledge
Other resources
Learn more about the Flutter framework from the following pages:
Flutter basics
Introduction to widgets
Building layouts tutorial
Add interactivity tutorial
Apply your existing knowledge
Flutter for Android developers
From Java to Dart codelab
Flutter for SwiftUI developers
Flutter for UIKit developers
Flutter for React Native developers
Flutter for web developers
Flutter for Xamarin.Forms developers
Other resources
Flutter samples
Flutter cookbook
Bootstrap into Dart: learn more about the language
Flutter API Docs | https://docs.flutter.dev/get-started/learn-more/index.html |
5017ead5ec61-1 | Flutter API Docs
The Complete Flutter Developer Bootcamp Using Dart
Udacity online Flutter training
Reach out to us at our mailing list. We’d love to hear from you!
Happy Fluttering!
Write your first Flutter app | https://docs.flutter.dev/get-started/learn-more/index.html |
fc4d8835cb65-0 | Set up an editor
Write your first Flutter app
Test drive
Get started
Test drive
This page describes how to create a new Flutter app from templates, run it,
and experience “hot reload” after you make changes to the app.
Select your development tool of choice for writing, building, and running
Flutter apps.
Visual Studio Code
Android Studio and IntelliJ
Terminal & editor
Create the app
Invoke View > Command Palette.
Type “flutter”, and select the Flutter: New Project.
Select Application.
Create or select the parent directory for the new project folder.
Enter a project name, such as my_app, and press Enter.
Wait for project creation to complete and the main.dart
file to appear. | https://docs.flutter.dev/get-started/test-drive/index.html |
fc4d8835cb65-1 | Wait for project creation to complete and the main.dart
file to appear.
The above commands create a Flutter project directory called my_app that
contains a simple demo app that uses Material Components.
Note:
When creating a new Flutter app, some Flutter IDE plugins ask for a
company domain name in reverse order, something like com.example.
The company domain name and project name are used together as the
package name for Android (the Bundle ID for iOS) when the app is released.
If you think that the app might be released,
it’s better to specify the package name now.
The package name can’t be changed once the app is released,
so make the name unique.
Warning:
If VS Code was running during your initial Flutter setup,
you might need to restart it for VS Code’s Flutter plugin to detect the Flutter SDK. | https://docs.flutter.dev/get-started/test-drive/index.html |
fc4d8835cb65-2 | Tip:
The code for your app is in lib/main.dart.
For a high-level description of what each code block does,
see the comments at the top of that file.
Run the app
Locate the VS Code status bar
(the blue bar at the bottom of the window):
Select a device from the Device Selector area.
For details, see Quickly switching between Flutter devices.
If no device is available, and you want to use a device simulator,
click No Devices and click
Start iOS Simulator to launch a simulator.
Warning:
You might not see Start iOS Simulator option
when you click No Devices in VS Code.
If you’re on Mac, then you might have to run following command
in terminal to launch a simulator. | https://docs.flutter.dev/get-started/test-drive/index.html |
fc4d8835cb65-3 | $ open -a simulator
On Windows or Linux, it’s not possible to launch an iOS simulator.
To setup a real device, follow the device-specific instructions
on the Install page for your OS.
Invoke Run > Start Debugging or press F5.
Wait for the app to launch—progress is printed
in the Debug Console view.
After the app build completes, you’ll see the starter app on your device.
Try hot reload
Flutter offers a fast development cycle with Stateful Hot Reload,
the ability to reload the code of a live running app without
restarting or losing app state.
Make a change to app source,
tell your IDE or command-line tool that you want to hot reload,
and see the change in your simulator, emulator, or device.
Open lib/main.dart.
Change the string
'You have pushed the button this many times' | https://docs.flutter.dev/get-started/test-drive/index.html |
fc4d8835cb65-4 | Change the string
'You have pushed the button this many times'
to
'You have clicked the button this many times'
Important:
Do not stop your app. Let your app run.
Save your changes: invoke Save All, or click Hot Reload
.
You’ll see the updated string in the running app almost immediately.
Profile or release runs
Important:
Do not test the performance of your app with debug and
hot reload enabled.
So far you’ve been running your app in debug mode. Debug
mode trades performance for useful developer features such
as hot reload and step debugging. It’s not unexpected to
see slow performance and janky animations in debug mode.
Once you are ready to analyze performance or release your
app, you’ll want to use Flutter’s “profile” or “release”
build modes. For more details, see Flutter’s build modes. | https://docs.flutter.dev/get-started/test-drive/index.html |
fc4d8835cb65-5 | Important:
If you’re concerned about the package size of your app,
see Measuring your app’s size.
Create the app
Open the IDE and select New Flutter Project.
Select Flutter, verify the Flutter SDK path with the SDK’s location.
Then click Next.
Enter a project name (for example, my_app).
Select Application as the project type.
Then click Next.
Click Finish.
Wait for Android Studio to create the project. | https://docs.flutter.dev/get-started/test-drive/index.html |
fc4d8835cb65-6 | Click Finish.
Wait for Android Studio to create the project.
Note:
When creating a new Flutter app, some Flutter IDE plugins ask for a
company domain name in reverse order, something like com.example.
The company domain name and project name are used together as the
package name for Android (the Bundle ID for iOS) when the app is released.
If you think that the app might be released,
it’s better to specify the package name now.
The package name can’t be changed once the app is released,
so make the name unique.
The above commands create a Flutter project directory
called my_app that contains a simple demo app that
uses Material Components.
Tip:
The code for your app is in lib/main.dart.
For a high-level description of what each code block does,
see the comments at the top of that file.
Run the app
Locate the main Android Studio toolbar: | https://docs.flutter.dev/get-started/test-drive/index.html |
fc4d8835cb65-7 | Run the app
Locate the main Android Studio toolbar:
In the target selector, select an Android device for running the app.
If none are listed as available,
select Tools > AVD Manager and create one there.
For details, see Managing AVDs.
Click the run icon in the toolbar, or invoke the menu item Run > Run.
After the app build completes, you’ll see the starter app on your device.
Try hot reload
Flutter offers a fast development cycle with Stateful Hot Reload,
the ability to reload the code of a live running app without
restarting or losing app state.
Make a change to app source,
tell your IDE or command-line tool that you want to hot reload,
and see the change in your simulator, emulator, or device.
Open lib/main.dart.
Change the string
'You have pushed the button this many times'
to | https://docs.flutter.dev/get-started/test-drive/index.html |
fc4d8835cb65-8 | 'You have pushed the button this many times'
to
'You have clicked the button this many times'
Important:
Do not stop your app. Let your app run.
Save your changes: invoke Save All, or click Hot Reload
.
You’ll see the updated string in the running app almost immediately.
Profile or release runs
Important:
Do not test the performance of your app with debug and
hot reload enabled.
So far you’ve been running your app in debug mode. Debug
mode trades performance for useful developer features such
as hot reload and step debugging. It’s not unexpected to
see slow performance and janky animations in debug mode.
Once you are ready to analyze performance or release your
app, you’ll want to use Flutter’s “profile” or “release”
build modes. For more details, see Flutter’s build modes. | https://docs.flutter.dev/get-started/test-drive/index.html |
fc4d8835cb65-9 | Important:
If you’re concerned about the package size of your app,
see Measuring your app’s size.
Create the app
Use the flutter create command to create a new project:
flutter create my_app
cd my_app
It is also possible to pass other arguments to flutter create,
such as the project name, the organization name,
or to specify the programming language used for the native platform:
flutter create
-project-name my_app
-org dev.flutter
-android-language java
-ios-language objc my_app
cd my_app
The command creates a Flutter project directory called my_app that
contains a simple demo app that uses Material Components. | https://docs.flutter.dev/get-started/test-drive/index.html |
fc4d8835cb65-10 | Tip:
The code for your app is in lib/main.dart.
For a high-level description of what each code block does,
see the comments at the top of that file.
Run the app
Check that an Android device is running.
If none are shown, follow the device-specific instructions
on the Install page for your OS.
$ flutter devices
Run the app with the following command:
$ flutter run
After the app build completes, you’ll see the starter app on your device.
Try hot reload
Flutter offers a fast development cycle with Stateful Hot Reload,
the ability to reload the code of a live running app without
restarting or losing app state.
Make a change to app source,
tell your IDE or command-line tool that you want to hot reload,
and see the change in your simulator, emulator, or device.
Open lib/main.dart. | https://docs.flutter.dev/get-started/test-drive/index.html |
fc4d8835cb65-11 | Open lib/main.dart.
Change the string
'You have pushed the button this many times'
to
'You have clicked the button this many times'
Important:
Do not stop your app. Let your app run.
Save your changes.
Type r in the terminal window.
You’ll see the updated string in the running app almost immediately.
Profile or release runs
Important:
Do not test the performance of your app with debug and
hot reload enabled. | https://docs.flutter.dev/get-started/test-drive/index.html |
fc4d8835cb65-12 | So far you’ve been running your app in debug mode. Debug
mode trades performance for useful developer features such
as hot reload and step debugging. It’s not unexpected to
see slow performance and janky animations in debug mode.
Once you are ready to analyze performance or release your
app, you’ll want to use Flutter’s “profile” or “release”
build modes. For more details, see Flutter’s build modes.
Important:
If you’re concerned about the package size of your app,
see Measuring your app’s size.
Set up an editor
Write your first Flutter app | https://docs.flutter.dev/get-started/test-drive/index.html |
b924243700b7-0 | Flutter documentation
New to Flutter?
Docs
Videos
Want to skill up?
Get started
Set up your environment and start building.
Widgets catalog
Dip into the rich set of Flutter widgets available in the SDK.
API docs
Bookmark the API reference docs for the Flutter framework.
Cookbook
Browse the cookbook for many easy Flutter recipes.
Samples
Check out the Flutter examples.
Videos
View the many videos on the Flutter YouTube channel.
To see changes to the site since our last release,
see What’s new.
New to Flutter?
Once you’ve gone through Get started,
including Write your first Flutter app,
here are some next steps.
Docs | https://docs.flutter.dev/index.html |
b924243700b7-1 | Docs
Coming from another platform? Check out Flutter for:
Android, SwiftUI, UIKit, React Native, and
Xamarin.Forms developers.
Building layouts
Learn how to create layouts in Flutter,
where everything is a widget.
Understanding constraints
Once you understand that “Constraints
flow down. Sizes flow up. Parents set
positions”, then you are well on your
way to understanding Flutter’s layout model.
Adding interactivity to your Flutter app
Learn how to add a stateful widget to your app.
A tour of the Flutter widget framework
Learn more about Flutter’s react-style framework.
FAQ
Get the answers to frequently asked questions.
Videos | https://docs.flutter.dev/index.html |
b924243700b7-2 | Get the answers to frequently asked questions.
Videos
Check out the Introducing Flutter series.
Learn Flutter basics like
how do I make my first Flutter app?
In Flutter, “everything is a widget”!
Learn more about Stateless and Stateful
widgets in What is State?
Only have 60 seconds? Learn how to build and deploy a Flutter App!
Want to skill up?
Dive deeper into how Flutter works under the hood!
Learn why you write standalone widgets instead of
using helper methods or
what is “BuildContext” and how is it used?
To learn about all of the Flutter video series,
see our videos page.
We release new videos almost every week on the Flutter YouTube channel:
Explore more Flutter videos
The documentation on this site reflects the
latest stable release of Flutter. | https://docs.flutter.dev/index.html |
269a0da192b3-0 | Flutter and Dart team job openings
The Flutter and Dart teams aren’t currently hiring.
Thanks for your interest! | https://docs.flutter.dev/jobs/index.html |
521d3d2e37bf-0 | Measuring your app's size
Debug builds are not representative
Checking the total size
Estimating total size
Android
iOS
Breaking down the size
Deeper analysis in DevTools
Reducing app size
Many developers are concerned with the size of their compiled app. As the APK,
app bundle, or IPA version of a Flutter app is self-contained and holds all the
code and assets needed to run the app, its size can be a concern. The larger an
app, the more space it requires on a device, the longer it takes to download,
and it may break the limit of useful features like Android instant apps.
Debug builds are not representative | https://docs.flutter.dev/perf/app-size/index.html |
521d3d2e37bf-1 | Debug builds are not representative
By default, launching your app with flutter run,
or by clicking the Play button in your IDE
(as used in Test drive and
Write your first Flutter app),
generates a debug build of the Flutter app.
The app size of a debug build is large due to
the debugging overhead that allows for hot reload
and source-level debugging. As such, it is not representative of a production
app end users download.
Checking the total size
A default release build, such as one created by flutter build apk or
flutter build ios, is built to conveniently assemble your upload package
to the Play Store and App Store. As such, they’re also not representative of
your end-users’ download size. The stores generally reprocess and split
your upload package to target the specific downloader and the downloader’s
hardware, such as filtering for assets targeting the phone’s DPI, filtering
native libraries targeting the phone’s CPU architecture.
Estimating total size | https://docs.flutter.dev/perf/app-size/index.html |
521d3d2e37bf-2 | Estimating total size
To get the closest approximate size on each platform, use the following
instructions.
Android
Follow the Google Play Console’s instructions for checking app download and
install sizes.
Produce an upload package for your application:
flutter build appbundle
Log into your Google Play Console. Upload your application binary by drag
dropping the .aab file.
View the application’s download and install size in the Android vitals ->
App size tab.
The download size is calculated based on an XXXHDPI (~640dpi) device on an
arm64-v8a architecture. Your end users’ download sizes may vary depending on
their hardware.
The top tab has a toggle for download size and install size. The page also
contains optimization tips further below.
iOS
Create an Xcode App Size Report. | https://docs.flutter.dev/perf/app-size/index.html |
521d3d2e37bf-3 | iOS
Create an Xcode App Size Report.
First, by configuring the app version and build as described in the
iOS create build archive instructions.
Then:
Run flutter build ipa --export-method development.
Run open build/ios/archive/*.xcarchive to open the archive in Xcode.
Click Distribute App.
Select a method of distribution. Development is the simplest if you don’t
intend to distribute the application.
In App Thinning, select ‘all compatible device variants’.
Select Strip Swift symbols.
Sign and export the IPA. The exported directory contains
App Thinning Size Report.txt with details about your projected
application size on different devices and versions of iOS.
The App Size Report for the default demo app in Flutter 1.17 shows: | https://docs.flutter.dev/perf/app-size/index.html |
521d3d2e37bf-4 | The App Size Report for the default demo app in Flutter 1.17 shows:
In this example, the app has an approximate
download size of 5.4 MB and an approximate
install size of 13.7 MB on an iPhone12,1 (Model ID / Hardware
number for iPhone 11)
and iPhone11,8 (iPhone XR) running iOS 13.0.
To measure an iOS app exactly,
you have to upload a release IPA to Apple’s
App Store Connect (instructions)
and obtain the size report from there.
IPAs are commonly larger than APKs as explained
in How big is the Flutter engine?, a
section in the Flutter FAQ.
Breaking down the size
Starting in Flutter version 1.22 and DevTools version 0.9.1,
a size analysis tool is included to help developers understand the breakdown
of the release build of their application. | https://docs.flutter.dev/perf/app-size/index.html |
521d3d2e37bf-5 | Warning:
As stated in the checking total size section
above, an upload package is not representative of your end users’ download
size. Be aware that redundant native library architectures and asset densities
seen in the breakdown tool can be filtered by the Play Store and App Store.
The size analysis tool is invoked by passing the --analyze-size flag when
building:
flutter build apk --analyze-size
flutter build appbundle --analyze-size
flutter build ios --analyze-size
flutter build linux --analyze-size
flutter build macos --analyze-size
flutter build windows --analyze-size
This build is different from a standard release build in two ways.
The tool compiles Dart in a way that records code size usage of Dart
packages. | https://docs.flutter.dev/perf/app-size/index.html |
521d3d2e37bf-6 | The tool displays a high level summary of the size breakdown
in the terminal, and leaves a *-code-size-analysis_*.json file for more
detailed analysis in DevTools.
In addition to analyzing a single build, two builds can also be diffed by
loading two *-code-size-analysis_*.json files into DevTools. See
DevTools documentation for details.
Through the summary, you can get a quick idea of the size usage per category
(such as asset, native code, Flutter libraries, etc). The compiled Dart
native library is further broken down by package for quick analysis.
Warning:
This tool on iOS creates a .app rather than an IPA. Use this tool to
evaluate the relative size of the .app’s content. To get
a closer estimate of the download size, reference the
Estimating total size section above.
Deeper analysis in DevTools | https://docs.flutter.dev/perf/app-size/index.html |
521d3d2e37bf-7 | Deeper analysis in DevTools
The *-code-size-analysis_*.json file produced above can be further
analyzed in deeper detail in DevTools where a tree or a treemap view can
break down the contents of the application into the individual file level and
up to function level for the Dart AOT artifact.
This can be done by flutter pub global run devtools, selecting
Open app size tool and uploading the JSON file.
For further information on using the DevTools app size tool, see
DevTools documentation.
Reducing app size
When building a release version of your app,
consider using the --split-debug-info tag.
This tag can dramatically reduce code size.
For an example of using this tag, see
Obfuscating Dart code.
Some other things you can do to make your app smaller are:
Remove unused resources
Minimize resource imported from libraries
Compress PNG and JPEG files | https://docs.flutter.dev/perf/app-size/index.html |
4dcafa2bd490-0 | More thoughts about performance
What is performance?
Why is performance important?
1. A performance report is easy to consume
2. Performance has little ambiguity
3. Performance is comparable and convertible
4. Performance is fair
How to make performance useful
What is performance?
Performance is a set of quantifiable properties of a performer.
In this context, performance isn’t the execution of an action itself;
it’s how well something or someone performs. Therefore, we use the adjective
performant. | https://docs.flutter.dev/perf/appendix/index.html |
4dcafa2bd490-1 | While the how well part can, in general, be described in natural languages,
in our limited scope, the focus is on something that is quantifiable as a real
number. Real numbers include integers and 0/1 binaries as special cases.
Natural language descriptions are still very important. For example, a news
article that heavily criticizes Flutter’s performance by just using words
without any numbers (a quantifiable value) could still be meaningful, and it
could have great impacts. The limited scope is chosen only because of our
limited resources.
The required quantity to describe performance is often referred to as a
metric.
To navigate through countless performance issues and metrics, you can categorize
based on performers.
For example, most of the content on this website is about the Flutter app
performance, where the performer is a Flutter app. Infra performance is also
important to Flutter, where the performers are build bots and CI task runners:
they heavily affect how fast Flutter can incorporate code changes, to improve
the app’s performance. | https://docs.flutter.dev/perf/appendix/index.html |
4dcafa2bd490-2 | Here, the scope was intentionally broadened to include performance issues other
than just app performance issues because they can share many tools regardless of
who the performers are. For example, Flutter app performance and infra
performance might share the same dashboard and similar alert mechanisms.
Broadening the scope also allows performers to be included that traditionally
are easy to ignore. Document performance is such an example. The performer
could be an API doc of the SDK, and a metric could be: the percentage of readers
who find the API doc useful.
Why is performance important?
Answering this question is not only crucial for validating the work in
performance, but also for guiding the performance work in order to be more
useful. The answer to “why is performance important?” often is also the answer
to “how is performance useful?”
Simply speaking, performance is important and useful because, in the scope,
performance must have quantifiable properties or metrics. This implies:
A performance report is easy to consume. | https://docs.flutter.dev/perf/appendix/index.html |
4dcafa2bd490-3 | A performance report is easy to consume.
Performance has little ambiguity.
Performance is comparable and convertible.
Performance is fair.
Not that non-performance, or non-measurable issues or descriptions are not
important. They’re meant to highlight the scenarios where performance can be
more useful.
1. A performance report is easy to consume
Performance metrics are numbers. Reading a number is much easier than reading a
passage. For example, it probably takes an engineer 1 second to consume the
performance rating as a number from 1 to 5. It probably takes the same engineer
at least 1 minute to read the full, 500-word feedback summary. | https://docs.flutter.dev/perf/appendix/index.html |
4dcafa2bd490-4 | If there are many numbers, it’s easy to summarize or visualize them for quick
consumption. For example, you can quickly consume millions of numbers by
looking at its histogram, average, quantiles, and so on. If a metric has a
history of thousands of data points, then you can easily plot a timeline to
read its trend.
On the other hand, having n number of 500-word texts almost guarantees an
n-time cost to consume those texts. It would be a daunting task to analyze
thousands of historical descriptions, each having 500 words.
2. Performance has little ambiguity | https://docs.flutter.dev/perf/appendix/index.html |
4dcafa2bd490-5 | 2. Performance has little ambiguity
Another advantage of having performance as a set of numbers is its unambiguity.
When you want an animation to have a performance of 20 ms per frame or
50 fps, there’s little room for different interpretations about the numbers. On
the other hand, to describe the same animation in words, someone might call it
good, while someone else might complain that it’s bad. Similarly, the same
word or phrase could be interpreted differently by different people. You might
interpret an OK frame rate to be 60 fps, while someone else might interpret it
to be 30 fps. | https://docs.flutter.dev/perf/appendix/index.html |
4dcafa2bd490-6 | Numbers can still be noisy. For example, the measured time per frame might
be a true computation time of this frame, plus a random amount of time (noise)
that CPU/GPU spends on some unrelated work. Hence, the metric fluctuates.
Nevertheless, there’s no ambiguity of what the number means. And, there are
also rigorous theory and testing tools to handle such noise. For example, you
could take multiple measurements to estimate the distribution of a random
variable, or you could take the average of many measurements to eliminate the
noise by the law of large numbers.
3. Performance is comparable and convertible | https://docs.flutter.dev/perf/appendix/index.html |
4dcafa2bd490-7 | 3. Performance is comparable and convertible
Performance numbers not only have unambiguous meanings, but they also have
unambiguous comparisons. For example, there’s no doubt that 5 is greater than 4.
On the other hand, it might be subjective to figure out whether excellent is
better or worse than superb. Similarly, could you figure out whether epic is
better than legendary? Actually, the phrase strongly exceeds expectations
could be better than superb in someone’s interpretation. It only becomes
unambiguous and comparable after a definition that maps strongly exceeds
expectations to 4 and superb to 5. | https://docs.flutter.dev/perf/appendix/index.html |
4dcafa2bd490-8 | Numbers are also easily convertible using formulas and functions. For example,
60 fps can be converted to 16.67 ms per frame. A frame’s rendering
time x (ms) can be converted to a binary indicator
isSmooth = [x <= 16] = (x <= 16 ? 1 :0). Such conversion can be compounded or
chained, so you can get a large variety of quantities using a single
measurement without any added noise or ambiguity. The converted quantity can
then be used for further comparisons and consumption. Such conversions are
almost impossible if you’re dealing with natural languages.
4. Performance is fair
If issues rely on verbose words to be discovered, then an unfair advantage is
given to people who are more verbose (more willing to chat or write) or those
who are closer to the development team, who have a larger bandwidth and lower
cost for chatting or face-to-face meetings. | https://docs.flutter.dev/perf/appendix/index.html |
4dcafa2bd490-9 | By having the same metrics to detect problems no matter how far away or how
silent the users are, we can treat all issues fairly. That, in turn,
allows us to focus on the right issues that have greater impact.
How to make performance useful
The following summarizes the 4 points discussed here, from a slightly different
perspective:
Make performance metrics easy to consume. Do not overwhelm the readers with a
lot of numbers (or words). If there are many numbers, then try to summarize
them into a smaller set of numbers (for example, summarize many numbers into
a single average number). Only notify readers when the numbers change
significantly (for example, automatic alerts on spikes or regressions). | https://docs.flutter.dev/perf/appendix/index.html |
4dcafa2bd490-10 | Make performance metrics as unambiguous as possible. Define the unit that the
number is using. Precisely describe how the number is measured. Make the
number easily reproducible. When there’s a lot of noise, try to show the full
distribution, or eliminate the noise as much as possible by aggregating many
noisy measurements.
Make it easy to compare performance. For example, provide a timeline to
compare the current version with the old version. Provide ways and tools to
convert one metric to another. For example, if we can convert both memory
increase and fps drops into the number of users dropped or revenue lost in
dollars, then we can compare them and make an informed trade-off.
Make performance metrics monitor a population that is as wide as possible,
so no one is left behind. | https://docs.flutter.dev/perf/appendix/index.html |
0fb8076e2896-0 | Performance best practices
Minimize expensive operations
Control build() cost
Use saveLayer() thoughtfully
Why is saveLayer expensive?
When is saveLayer required?
Debugging calls to saveLayer
Minimizing calls to saveLayer
Minimize use of opacity and clipping
Implement grids and lists thoughtfully
Be lazy!
Avoid intrinsics
Minimize layout passes caused by intrinsic operations
What is an intrinsic pass?
Debugging intrinsic passes
Avoiding intrinsic passes
Build and display frames in 16ms
Pitfalls
Resources
Note:
To learn how to use the Performance View
(part of Flutter DevTools)
for debugging performance issues,
see Using the Performance view. | https://docs.flutter.dev/perf/best-practices/index.html |
0fb8076e2896-1 | Generally, Flutter applications are performant by default,
so you only need to avoid common pitfalls to get excellent
performance. These best practice recommendations will help you
write the most performant Flutter app possible.
Note:
If you are writing web apps in Flutter, you might be interested
in a series of articles, written by the Flutter Material team,
after they modified the Flutter Gallery app to make it more
performant on the web:
Optimizing performance in Flutter web apps with tree
shaking and deferred loading
Improving perceived performance with image placeholders,
precaching, and disabled navigation transitions
Building performant Flutter widgets | https://docs.flutter.dev/perf/best-practices/index.html |
0fb8076e2896-2 | Building performant Flutter widgets
How do you design a Flutter app to most efficiently
render your scenes? In particular, how do you ensure
that the painting code generated by the
framework is as efficient as possible?
Some rendering and layout operations are known
to be slow, but can’t always be avoided.
They should be used thoughtfully,
following the guidance below.
Minimize expensive operations
Some operations are more expensive than others,
meaning that they consume more resources.
Obviously, you want to only use these operations
when necessary. How you design and implement your
app’s UI can have a big impact on how efficiently it runs.
Control build() cost
Here are some things to keep in mind when designing your UI:
Avoid repetitive and costly work in build() methods
since build() can be invoked frequently when
ancestor widgets rebuild. | https://docs.flutter.dev/perf/best-practices/index.html |
0fb8076e2896-3 | Avoid overly large single widgets with a large build() function.
Split them into different widgets based on encapsulation
but also on how they change:
When setState() is called on a State object,
all descendent widgets rebuild. Therefore,
localize the setState() call to the part of
the subtree whose UI actually needs to change.
Avoid calling setState() high up in the tree
if the change is contained to a small part of the tree.
The traversal to rebuild all descendents stops when the
same instance of the child widget as the previous
frame is re-encountered. This technique is heavily
used inside the framework for optimizing
animations where the animation doesn’t affect the child subtree.
See the TransitionBuilder pattern and
the source code for SlideTransition,
which uses this principle to avoid rebuilding its | https://docs.flutter.dev/perf/best-practices/index.html |
0fb8076e2896-4 | which uses this principle to avoid rebuilding its
descendents when animating.
(“Same instance” is evaluated using operator ==,
but see the pitfalls section at the end of this page
for advice on when to avoid overriding operator ==.)
Use const constructors on widgets as much as possible,
since they allow Flutter to short-circuit most
of the rebuild work. To be automatically reminded
to use const when possible, enable the
recommended lints from the flutter_lints package.
For more information, check out the
flutter_lints migration guide.
To create reusable pieces of UIs,
prefer using a StatelessWidget
rather than a function. | https://docs.flutter.dev/perf/best-practices/index.html |
0fb8076e2896-5 | For more information, check out:
Performance considerations,
part of the StatefulWidget API doc
Widgets vs helper methods,
a video from the official Flutter YouTube
channel that explains why widgets
(especially widgets with const constructors)
are more performant than functions.
Use saveLayer() thoughtfully
Some Flutter code uses saveLayer(), an expensive operation,
to implement various visual effects in the UI.
Even if your code doesn’t explicitly call saveLayer(),
other widgets or packages that you use might call it behind the scenes.
Perhaps your app is calling saveLayer() more than necessary;
excessive calls to saveLayer() can cause jank.
Why is saveLayer expensive? | https://docs.flutter.dev/perf/best-practices/index.html |
0fb8076e2896-6 | Why is saveLayer expensive?
Calling saveLayer() allocates an offscreen buffer
and drawing content into the offscreen buffer might
trigger a render target switch.
The GPU wants to run like a firehose,
and a render target switch forces the GPU
to redirect that stream temporarily and then
direct it back again. On mobile GPUs this is
particularly disruptive to rendering throughput.
When is saveLayer required?
At runtime, if you need to dynamically display various shapes
coming from a server (for example), each with some transparency,
that might (or might not) overlap,
then you pretty much have to use saveLayer().
Debugging calls to saveLayer
DevTools timeline; learn when
your scene uses
DevTools Performance view.
Minimizing calls to saveLayer
Can you avoid calls to saveLayer?
It might require rethinking of how you
create your visual effects: | https://docs.flutter.dev/perf/best-practices/index.html |
0fb8076e2896-7 | If the calls are coming from your code, can you
reduce or eliminate them?
For example, perhaps your UI overlaps two shapes,
each having non-zero transparency:
If they always overlap in the same amount,
in the same way, with the same transparency,
you can precalculate what this overlapped,
semi-transparent object looks like, cache it,
and use that instead of calling saveLayer().
This works with any static shape you can precalculate.
Can you refactor your painting logic to avoid
overlaps altogether?
If the calls are coming from a package that you don’t own,
contact the package owner and ask why
these calls are necessary. Can they be reduced or
eliminated? If not, you might need to find another
package, or write your own.
Note to package owners:
As a best practice, consider providing documentation
for when saveLayer might be necessary for your package,
how it might be avoided, and when it can’t be avoided. | https://docs.flutter.dev/perf/best-practices/index.html |
0fb8076e2896-8 | Other widgets that might trigger saveLayer()
and are potentially costly:
ShaderMask
ColorFilter
Chip—might trigger a call to saveLayer() if
disabledColorAlpha != 0xff
Text—might trigger a call to saveLayer()
if there’s an overflowShader
Minimize use of opacity and clipping
Opacity is another expensive operation, as is clipping.
Here are some tips you might find to be useful:
Use the Opacity widget only when necessary.
See the Transparent image section in the Opacity
API page for an example of applying opacity directly
to an image, which is faster than using the Opacity
widget.
Instead of wrapping simple shapes or text
in an Opacity widget, it’s usually faster to
just draw them with a semitransparent color.
(Though this only works if there are no overlapping
bits in the to-be-drawn shape.) | https://docs.flutter.dev/perf/best-practices/index.html |
0fb8076e2896-9 | To implement fading in an image, consider using the
FadeInImage widget, which applies a gradual
opacity using the GPU’s fragment shader.
For more information, check out the Opacity docs.
Clipping doesn’t call saveLayer() (unless
explicitly requested with Clip.antiAliasWithSaveLayer),
so these operations aren’t as expensive as Opacity,
but clipping is still costly, so use with caution.
By default, clipping is disabled (Clip.none),
so you must explicitly enable it when needed.
To create a rectangle with rounded corners,
instead of applying a clipping rectangle,
consider using the borderRadius property offered
by many of the widget classes.
Implement grids and lists thoughtfully
How your grids and lists are implemented
might be causing performance problems for your app.
This section describes an important best
practice when creating grids and lists,
and how to determine whether your app uses
excessive layout passes. | https://docs.flutter.dev/perf/best-practices/index.html |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.