id
stringlengths 14
17
| text
stringlengths 23
1.11k
| source
stringlengths 35
114
|
---|---|---|
8c0e1648bb75-12 | From the same directory:
all the .dll files
the data directory
The Visual C++ redistributables.
You can use any of the methods shown in the
deployment example walkthroughs on the Microsoft site
to ensure that end users have the C++ redistributables.
If you use the application-local option, you need to copy:
msvcp140.dll
vcruntime140.dll
vcruntime140_1.dll
Place the DLL files in the directory next to the executable
and the other DLLs, and bundle them together in a zip file.
The resulting structure looks something like this:
Release
│ flutter_windows.dll
│ msvcp140.dll
│ my_app.exe
│ vcruntime140.dll
│ vcruntime140_1.dll
│
└───data
│ │ app.so
│ │ icudtl.dat | https://docs.flutter.dev/development/platform-integration/windows/building/index.html |
8c0e1648bb75-13 | ...
At this point if desired it would be relatively simple to
add this folder to a Windows installer such as Inno Setup, WiX, etc. | https://docs.flutter.dev/development/platform-integration/windows/building/index.html |
72febf8be152-0 | Migrate a Windows project to support dark title bars
Platform integration
Windows
Migrate a Windows project to support dark title bars
Migration steps
Example
Projects created before Flutter 3.7 have light title bars even
when the Windows theme is dark mode. Projects created before
Flutter 3.7 need to be migrated to support dark title bars.
Migration steps
Your project can be updated using these steps:
Verify you are on Flutter version 3.7 or newer using flutter --version
If needed, use flutter upgrade to update to the latest version of the
Flutter SDK
Backup your project, possibly using git or some other version control system
Delete the following files:
windows/runner/CMakeLists.txt
windows/runner/win32_window.cpp
windows/runner/win32_window.h | https://docs.flutter.dev/development/platform-integration/windows/dark-mode-migration/index.html |
72febf8be152-1 | Run flutter create --platforms=windows .
Review the changes to the following files:
windows/runner/CMakeLists.txt
windows/runner/win32_window.cpp
windows/runner/win32_window.h
Verify your app builds using flutter build windows
Note:
Follow the run loop migration guide if the build fails
with the following error message:
Example
PR 862 shows the migration work for the
Flutter Gallery app. | https://docs.flutter.dev/development/platform-integration/windows/dark-mode-migration/index.html |
044100ae7410-0 | Windows
Platform integration
Windows
Topics:
Building Windows apps
Run loop migration
Version information migration
Dark mode migration | https://docs.flutter.dev/development/platform-integration/windows/index.html |
f2f45bce2ad3-0 | Migrate a Windows project to the idiomatic run loop
Platform integration
Windows
Migrate a Windows project to the idiomatic run loop
Migration steps
Flutter 2.5 replaced Windows apps’ run loop with an idiomatic
Windows message pump to reduce CPU usage.
Projects created before Flutter version 2.5 need to be
migrated to get this improvement. You should follow the
migration steps below if the windows/runner/run_loop.h
file exists in your project.
Migration steps
Note:
As part of this migration, you must recreate your Windows project,
which clobbers any custom changes to the
files in the windows/runner folder. The following steps
include instructions for this scenario.
Your project can be updated using these steps:
Verify you are on Flutter version 2.5 or newer using flutter --version | https://docs.flutter.dev/development/platform-integration/windows/run-loop-migration/index.html |
f2f45bce2ad3-1 | Verify you are on Flutter version 2.5 or newer using flutter --version
If needed, use flutter upgrade to update to the latest version of the
Flutter SDK
Backup your project with git (or your preferred version control system),
since you need to reapply any local changes you’ve made (if any) to your
project in a later step
Delete all files under the windows/runner folder
Run flutter create --platforms=windows . to recreate the Windows project
Review the changes to files in the windows/runner folder
Reapply any custom changes made to the files in the
windows/runner folder prior to this migration
Verify that your app builds using flutter build windows | https://docs.flutter.dev/development/platform-integration/windows/run-loop-migration/index.html |
775486a5fa31-0 | Migrate a Windows project to set version information
Platform integration
Windows
Migrate a Windows project to set version information
Migration steps
Example
Flutter 3.3 added support for setting the Windows app’s version from
the pubspec.yaml file or through the --build-name and --build-number
build arguments. For more information, refer to the
Build and release a Windows app documentation.
Projects created before Flutter version 3.3 need to be migrated
to support versioning.
Migration steps
Your project can be updated using these steps:
Verify you are on Flutter version 3.3 or newer using flutter --version
If needed, use flutter upgrade to update to the latest version of the
Flutter SDK
Backup your project, possibly using git or some other version control system | https://docs.flutter.dev/development/platform-integration/windows/version-migration/index.html |
775486a5fa31-1 | Backup your project, possibly using git or some other version control system
Delete the windows/runner/CMakeLists.txt and windows/runner/Runner.rc
files
Run flutter create --platforms=windows .
Review the changes to your windows/runner/CMakeLists.txt and
windows/runner/Runner.rc files
Verify your app builds using flutter build windows
Note:
Follow the run loop migration guide if the build fails
with the following error message:
Example
PR 721 shows the migration work for the
Flutter Gallery app. | https://docs.flutter.dev/development/platform-integration/windows/version-migration/index.html |
d09c39894687-0 | Android Studio and IntelliJ
Tools
Android Studio and IntelliJ
Installation and setup
Updating the plugins
Creating projects
Creating a new project
Creating a new project from existing source code
Editing code and viewing issues
Running and debugging
Selecting a target
Run app without breakpoints
Run app with breakpoints
Fast edit and refresh development cycle
Show performance data
Editing tips for Flutter code
Assists & quick fixes
Wrap with new widget assist
Wrap widget list with new widget assist
Convert child to children assist
Live templates
Keyboard shortcuts
Hot reload vs. hot restart
Editing Android code in Android Studio with full IDE support
Editing Android code in IntelliJ IDEA
Tips and tricks
Troubleshooting | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-1 | Tips and tricks
Troubleshooting
Known issues and feedback
Android Studio and IntelliJ
Visual Studio Code
Installation and setup
Follow the Set up an editor
instructions to install the Dart and Flutter plugins.
Updating the plugins
Updates to the plugins are shipped on a regular basis.
You should be prompted in the IDE when an update is available.
To check for updates manually:
Open preferences (Android Studio > Check for Updates on macOS,
Help > Check for Updates on Linux).
If dart or flutter are listed, update them.
Creating projects
You can create a new project in one of several ways.
Creating a new project
To create a new Flutter project from the Flutter starter app template: | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-2 | To create a new Flutter project from the Flutter starter app template:
In the IDE, click New Project from the Welcome
window or File > New > Project from the main IDE window.
Specify the Flutter SDK path and click Next.
Enter your desired Project name, Description and Project location.
If you might publish this app, set the company domain.
Click Finish.
Setting the company domain
When creating a new app, some Flutter IDE plugins ask for an
organization name in reverse domain order,
something like com.example. Along with the name of the app,
this is used as the package name for Android, and the Bundle ID for iOS
when the app is released. If you think you might ever release this app,
it is better to specify these now. They cannot be changed once the app
is released. Your organization name should be unique.
Creating a new project from existing source code | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-3 | Creating a new project from existing source code
To create a new Flutter project containing existing Flutter source code
files:
In the IDE, click Create New Project from the
Welcome window or File > New > Project
from the main IDE window.
Important:
Do not use the New > Project from existing sources
option for Flutter projects.
Select Flutter in the menu, and click Next.
Under Project location enter, or browse to,
the directory holding your
existing Flutter source code files.
Click Finish.
Editing code and viewing issues
The Flutter plugin performs code analysis that enables the following:
Syntax highlighting.
Code completions based on rich type analysis.
Navigating to type declarations (Navigate > Declaration),
and finding type usages (Edit > Find > Find Usages). | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-4 | Viewing all current source code problems
(View > Tool Windows > Dart Analysis).
Any analysis issues are shown in the Dart Analysis pane:
Running and debugging
Note:
You can debug your app in a few ways.
Using DevTools, a suite of debugging and profiling
tools that run in a browser
and include the Flutter inspector.
Using Android Studio’s (or IntelliJ’s) built-in debugging
features, such as the ability to set breakpoints.
Using the Flutter inspector, directly available in
Android Studio and IntelliJ.
The instructions below describe features available in Android
Studio and IntelliJ. For information on launching DevTools,
see Running DevTools from Android Studio in the
DevTools docs.
Running and debugging are controlled from the main toolbar:
Selecting a target | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-5 | Running and debugging are controlled from the main toolbar:
Selecting a target
When a Flutter project is open in the IDE, you should see a set of
Flutter-specific buttons on the right-hand side of the toolbar.
Note:
If the Run and Debug buttons are disabled, and no targets are listed,
Flutter has not been able to discover any connected iOS or
Android devices or simulators.
You need to connect a device, or start a simulator, to proceed.
Locate the Flutter Target Selector drop-down button.
This shows a list of available targets.
Select the target you want your app to be started on.
When you connect devices, or start simulators,
additional entries appear.
Run app without breakpoints
Click the Play icon in the toolbar, or invoke Run > Run.
The bottom Run pane shows logs output.
Run app with breakpoints
If desired, set breakpoints in your source code. | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-6 | If desired, set breakpoints in your source code.
Click the Debug icon in the toolbar, or invoke Run > Debug.
The bottom Debugger pane shows Stack Frames and Variables.
The bottom Console pane shows detailed logs output.
Debugging is based on a default launch configuration.
To customize this, click the drop-down button to the right
of the device selector, and select Edit configuration.
Fast edit and refresh development cycle
Flutter offers a best-in-class developer cycle enabling you to see the effect
of your changes almost instantly with the Stateful Hot Reload feature.
To learn more, check out Hot reload.
Show performance data
Note:
To examine performance issues in Flutter, see the
Timeline view.
To view the performance data, including the widget rebuild
information, start the app in Debug mode, and then open
the Performance tool window using
View > Tool Windows > Flutter Performance. | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-7 | To see the stats about which widgets are being rebuilt, and how often,
click Show widget rebuild information in the Performance pane.
The exact count of the rebuilds for this frame displays in the second
column from the right. For a high number of rebuilds, a yellow spinning
circle displays. The column to the far right shows how many times a
widget was rebuilt since entering the current screen.
For widgets that aren’t rebuilt, a solid grey circle displays.
Otherwise, a grey spinning circle displays.
The app shown in this screenshot has been designed to deliver
poor performance, and the rebuild profiler gives you a clue
about what is happening in the frame that might cause poor
performance. The widget rebuild profiler is not a diagnostic
tool, by itself, about poor performance. | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-8 | The purpose of this feature is to make you aware when widgets are
rebuilding—you might not realize that this is happening when just
looking at the code. If widgets are rebuilding that you didn’t expect,
it’s probably a sign that you should refactor your code by splitting
up large build methods into multiple widgets.
This tool can help you debug at least four common performance issues:
The whole screen (or large pieces of it) are built by a single
StatefulWidget, causing unnecessary UI building. Split up the
UI into smaller widgets with smaller build() functions.
Offscreen widgets are being rebuilt. This can happen, for example,
when a ListView is nested in a tall Column that extends offscreen.
Or when the RepaintBoundary is not set for a list that extends
offscreen, causing the whole list to be redrawn.
The build() function for an AnimatedBuilder draws a subtree that
does not need to be animated, causing unnecessary rebuilds of static
objects. | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-9 | An Opacity widget is placed unnecessarily high in the widget tree.
Or, an Opacity animation is created by directly manipulating the
opacity property of the Opacity widget, causing the widget itself
and its subtree to rebuild.
You can click on a line in the table to navigate to the line
in the source where the widget is created. As the code runs,
the spinning icons also display in the code pane to help you
visualize which rebuilds are happening.
Note that numerous rebuilds doesn’t necessarily indicate a problem.
Typically you should only worry about excessive rebuilds if you have
already run the app in profile mode and verified that the performance
is not what you want.
And remember, the widget rebuild information is only available in
a debug build. Test the app’s performance on a real device in a profile
build, but debug performance issues in a debug build.
Editing tips for Flutter code
If you have additional tips we should share, let us know! | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-10 | If you have additional tips we should share, let us know!
Assists & quick fixes
Assists are code changes related to a certain code identifier.
A number of these are available when the cursor is placed on a
Flutter widget identifier, as indicated by the yellow lightbulb icon.
The assist can be invoked by clicking the lightbulb, or by using the
keyboard shortcut (Alt+Enter on Linux and Windows,
Option+Return on macOS), as illustrated here:
Quick Fixes are similar, only they are shown with a piece of code has an error
and they can assist in correcting it. They are indicated with a red lightbulb.
Wrap with new widget assist
This can be used when you have a widget that you want to wrap in a surrounding
widget, for example if you want to wrap a widget in a Row or Column.
Wrap widget list with new widget assist
Similar to the assist above, but for wrapping an existing list of
widgets rather than an individual widget. | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-11 | Convert child to children assist
Changes a child argument to a children argument,
and wraps the argument value in a list.
Live templates
Live templates can be used to speed up entering typical code structures.
They are invoked by typing their prefix, and then selecting it in the code
completion window:
The Flutter plugin includes the following templates:
Prefix stless: Create a new subclass of StatelessWidget.
Prefix stful: Create a new subclass of StatefulWidget and
its associated State subclass.
Prefix stanim: Create a new subclass of StatefulWidget and its
associated State subclass, including a field initialized with an
AnimationController.
You can also define custom templates in Settings > Editor > Live Templates.
Keyboard shortcuts
Hot reload
On macOS (keymap Mac OS X 10.5+ copy) the keyboard shortcuts are
Command+Option and Command+Backslash. | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-12 | Keyboard mappings can be changed in the IDE Preferences/Settings: Select
Keymap, then enter flutter into the search box in the upper right corner.
Right click the binding you want to change and Add Keyboard Shortcut.
Hot reload vs. hot restart
Hot reload works by injecting updated source code files into the running
Dart VM (Virtual Machine). This includes not only adding new classes,
but also adding methods and fields to existing classes,
and changing existing functions.
A few types of code changes cannot be hot reloaded though:
Global variable initializers
Static field initializers
The main() method of the app
For these changes you can fully restart your application,
without having to end your debugging session. To perform a hot restart,
don’t click the Stop button, simply re-click the Run button (if in a run
session) or Debug button (if in a debug session), or shift-click the ‘hot
reload’ button.
Editing Android code in Android Studio with full IDE support | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-13 | Editing Android code in Android Studio with full IDE support
Opening the root directory of a Flutter project doesn’t expose all the Android
files to the IDE. Flutter apps contain a subdirectory named android. If you
open this subdirectory as its own separate project in Android Studio, the IDE
will be able to fully support editing and refactoring all Android files (like
Gradle scripts).
If you already have the entire project opened as a Flutter app in Android
Studio, there are two equivalent ways to open the Android files on their own
for editing in the IDE. Before trying this, make sure that you’re on the latest
version of Android Studio and the Flutter plugins.
In the “project view”, you should see a subdirectory immediately under
the root of your flutter app named android. Right click on it,
then select Flutter > Open Android module in Android Studio. | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-14 | OR, you can open any of the files under the android subdirectory for
editing. You should then see a “Flutter commands” banner at the top of the
editor with a link labeled Open for Editing in Android Studio.
Click that link.
For both options, Android Studio gives you the option to use separate windows or
to replace the existing window with the new project when opening a second
project. Either option is fine.
If you don’t already have the Flutter project opened in Android studio,
you can open the Android files as their own project from the start:
Click Open an existing Android Studio Project on the Welcome
splash screen, or File > Open if Android Studio is already open.
Open the android subdirectory immediately under the flutter app root.
For example if the project is called flutter_app,
open flutter_app/android. | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-15 | If you haven’t run your Flutter app yet, you might see Android Studio report a
build error when you open the android project. Run flutter pub get in
the app’s root directory and rebuild the project by selecting Build > Make
to fix it.
Editing Android code in IntelliJ IDEA
To enable editing of Android code in IntelliJ IDEA, you need to configure the
location of the Android SDK:
In Preferences > Plugins, enable Android Support if you
haven’t already.
Right-click the android folder in the Project view, and select Open
Module Settings.
In the Sources tab, locate the Language level field, and
select level 8 or later.
In the Dependencies tab, locate the Module SDK field,
and select an Android SDK. If no SDK is listed, click New
and specify the location of the Android SDK.
Make sure to select an Android SDK matching the one used by
Flutter (as reported by flutter doctor).
Click OK. | https://docs.flutter.dev/development/tools/android-studio/index.html |
d09c39894687-16 | Click OK.
Tips and tricks
Flutter IDE cheat sheet, MacOS version
Flutter IDE cheat sheet, Windows & Linux version
Troubleshooting
Known issues and feedback
Important known issues that might impact your experience are documented
in the Flutter plugin README file.
All known bugs are tracked in the issue trackers:
Flutter plugin: GitHub issue tracker
Dart plugin: JetBrains YouTrack
We welcome feedback, both on bugs/issues and feature requests.
Prior to filing new issues:
Do a quick search in the issue trackers to see if the issue is already
tracked.
Make sure you have updated to the most recent version of the
plugin.
When filing new issues, include the output of flutter doctor. | https://docs.flutter.dev/development/tools/android-studio/index.html |
fe4b0dc19d5d-0 | Install and run DevTools from Android Studio
Tools
DevTools
Install and run DevTools from Android Studio
Install the Flutter plugin
Start an app to debug
Launch DevTools from the toolbar/menu
Launch DevTools from an action
Install the Flutter plugin
Install the Flutter plugin if you don’t already have it installed.
This can be done using the normal Plugins page in the IntelliJ
and Android Studio settings. Once that page is open,
you can search the marketplace for the Flutter plugin.
Start an app to debug
To open DevTools, you first need to run a Flutter app.
This can be accomplished by opening a Flutter project,
ensuring that you have a device connected,
and clicking the Run or Debug toolbar buttons.
Launch DevTools from the toolbar/menu | https://docs.flutter.dev/development/tools/devtools/android-studio/index.html |
fe4b0dc19d5d-1 | Launch DevTools from the toolbar/menu
Once an app is running,
you can start DevTools using one of the following:
Select the Open DevTools toolbar action in the Run view.
Select the Open DevTools toolbar action in the Debug view.
(if debugging)
Select the Open DevTools action from the More Actions
menu in the Flutter Inspector view.
Launch DevTools from an action
You can also open DevTools from an IntelliJ action.
Open the Find Action… dialog
(on a Mac, press Command+Shift+A), and search for the
Open DevTools action. When you select that action,
DevTools is installed (if it isn’t already), the DevTools server
launches, and a browser instance opens pointing to the DevTools app. | https://docs.flutter.dev/development/tools/devtools/android-studio/index.html |
fe4b0dc19d5d-2 | When opened with an IntelliJ action, DevTools is not connected
to a Flutter app. You’ll need to provide a service protocol port
for a currently running app. You can do this using the inline
Connect to a running app dialog. | https://docs.flutter.dev/development/tools/devtools/android-studio/index.html |
73ea98ef8e96-0 | Using the app size tool
Tools
DevTools
Using the app size tool
What is it?
What is “size information”?
Dart size information
How to use it
Analysis tab
Loading a size file
Treemap and table
Using the treemap
Dominator tree and call graph
Using the dominator tree
Using the call graph
Should I use the dominator tree or the call graph?
Diff tab
Loading size files
Treemap and table
Generating size files
Other resources
What is it?
The app size tool allows you to analyze the total size of your app.
You can view a single snapshot of “size information”
using the Analysis tab, or compare two different
snapshots of “size information” using the Diff tab. | https://docs.flutter.dev/development/tools/devtools/app-size/index.html |
73ea98ef8e96-1 | What is “size information”?
“Size information” contains size data for Dart code,
native code, and non-code elements of your app,
like the application package, assets and fonts. A “size
information” file contains data for the total picture
of your application size.
Dart size information
The Dart AOT compiler performs tree-shaking on your code
when compiling your application (profile or release mode
only—the AOT compiler is not used for debug builds,
which are JIT compiled). This means that the compiler
attempts to optimize your app’s size by removing
pieces of code that are unused or unreachable.
After the compiler optimizes your code as much as it can,
the end result can be summarized as the collection of packages,
libraries, classes, and functions that exist in the binary output,
along with their size in bytes. This is the Dart portion of
“size information” we can analyze in the app size tool to further
optimize Dart code and track down size issues. | https://docs.flutter.dev/development/tools/devtools/app-size/index.html |
73ea98ef8e96-2 | How to use it
If DevTools is already connected to a running application,
navigate to the “App Size” tab.
If DevTools is not connected to a running application, you can
access the tool from the landing page that appears once you have launched
DevTools (see installation instructions).
Analysis tab
The analysis tab allows you to inspect a single snapshot
of size information. You can view the hierarchical structure
of the size data using the treemap and table,
and you can view code attribution data
(for example, why a piece of code is included in your compiled
application) using the dominator tree and call graph.
Loading a size file
When you open the Analysis tab, you’ll see instructions
to load an app size file. Drag and drop an app size
file into the dialog, and click “Analyze Size”.
See Generating size files below for information on
generating size files.
Treemap and table | https://docs.flutter.dev/development/tools/devtools/app-size/index.html |
73ea98ef8e96-3 | Treemap and table
The treemap and table show the hierarchical data for your app’s size.
Using the treemap
A treemap is a visualization for hierarchical data.
The space is broken up into rectangles,
where each rectangle is sized and ordered by some quantitative
variable (in this case, size in bytes).
The area of each rectangle is proportional to the size
the node occupies in the compiled application. Inside
of each rectangle (call one A), there are additional
rectangles that exist one level deeper in the data
hierarchy (children of A).
To drill into a cell in the treemap, select the cell.
This re-roots the tree so that the selected cell becomes
the visual root of the treemap.
To navigate back, or up a level, use the breadcrumb
navigator at the top of the treemap.
Dominator tree and call graph | https://docs.flutter.dev/development/tools/devtools/app-size/index.html |
73ea98ef8e96-4 | Dominator tree and call graph
This section of the page shows code size attribution data
(for example, why a piece of code is included in your
compiled application). This data is visible
in the form of a dominator tree as well as a call graph.
Using the dominator tree
A dominator tree is a tree where each node’s
children are those nodes it immediately dominates.
A node a is said to “dominate” a node b if
every path to b must go through a.
In this example, package:a dominates package:d,
so the dominator tree for this data would look like:
This information is helpful for understanding why certain
pieces of code are present in your compiled application.
For example, if you are analyzing your app size and find
an unexpected package included in your compiled app, you can
use the dominator tree to trace the package to its root source.
Using the call graph | https://docs.flutter.dev/development/tools/devtools/app-size/index.html |
73ea98ef8e96-5 | Using the call graph
A call graph provides similar information to the dominator
tree in regards to helping you understand why code exists
in a compiled application. However, instead of showing
the one-to-many dominant relationships between nodes of code
size data like the dominator tree, the call graph shows the many-to-many
relationships that existing between nodes of code size data.
Again, using the following example:
The call graph for this data would link package:d
to its direct callers, package:b and package:c,
instead of its “dominator”, package:a.
This information is useful for understanding the
fine-grained dependencies of between pieces of your code
(packages, libraries, classes, functions).
Should I use the dominator tree or the call graph?
Use the dominator tree if you want to understand the
root cause for why a piece of code is included in your
application. Use the call graph if you want to understand
all the call paths to and from a piece of code. | https://docs.flutter.dev/development/tools/devtools/app-size/index.html |
73ea98ef8e96-6 | A dominator tree is an analysis or slice of call graph data,
where nodes are connected by “dominance” instead of
parent-child hierarchy. In the case where a parent node
dominates a child, the relationship in the call graph and the
dominator tree would be identical, but this is not always the case.
In the scenario where the call graph is complete
(an edge exists between every pair of nodes),
the dominator tree would show the that root is the
dominator for every node in the graph.
This is an example where the call graph would give
you a better understanding around why a piece of code is
included in your application.
Diff tab
The diff tab allows you to compare two snapshots of
size information. The two size information files
you are comparing should be generated from two different
versions of the same app; for example,
the size file generated before and after
changes to your code. You can visualize the
difference between the two data sets
using the treemap and table.
Loading size files | https://docs.flutter.dev/development/tools/devtools/app-size/index.html |
73ea98ef8e96-7 | Loading size files
When you open the Diff tab,
you’ll see instructions to load “old” and “new” size
files. Again, these files need to be generated from
the same application. Drag and drop these files into
their respective dialogs, and click Analyze Diff.
See Generating size files below for information
on generating these files.
Treemap and table
In the diff view, the treemap and tree table show
only data that differs between the two imported size files.
For questions about using the treemap, see Using the treemap above.
Generating size files
To use the app size tool, you’ll need to generate a
Flutter size analysis file. This file contains size
information for your entire application (native code,
Dart code, assets, fonts, etc.), and you can generate it using the
--analyze-size flag: | https://docs.flutter.dev/development/tools/devtools/app-size/index.html |
73ea98ef8e96-8 | This builds your application, prints a size summary
to the command line, and prints a line
telling you where to find the size analysis file.
In this example, import the build/apk-code-size-analysis_01.json
file into the app size tool to analyze further.
For more information, see App Size Documentation.
Other resources
To learn how to perform a step-by-step size analysis of
the Wonderous App using DevTools, check out the
App Size Tool tutorial. Various strategies
to reduce an app’s size are also discussed. | https://docs.flutter.dev/development/tools/devtools/app-size/index.html |
24e0ff14b2ab-0 | Install and run DevTools from the command line
Tools
DevTools
Install and run DevTools from the command line
Start an application to debug
Connect to a new app instance
To run Dart DevTools from the CLI, you must have dart on your path. Then
you can run the following command to launch DevTools:
To upgrade DevTools, upgrade your Dart SDK. If a newer Dart SDK
includes a newer version of DevTools, dart devtools will automatically
launch this version. If which dart points to the Dart SDK included in
your Flutter SDK, then DevTools will be upgraded when you upgrade your
Flutter SDK to a newer version.
When you run DevTools from the command line, you should see output that
looks something like:
Start an application to debug | https://docs.flutter.dev/development/tools/devtools/cli/index.html |
24e0ff14b2ab-1 | Start an application to debug
Next, start an app to connect to.
This can be either a Flutter application
or a Dart command-line application.
The command below specifies a Flutter app:
You need to have a device connected, or a simulator open,
for flutter run to work. Once the app starts, you’ll see a
message in your terminal that looks like the following:
Open the DevTools instance connected to your app
by opening the second link in Chrome.
This URL contains a security token,
so it’s different for each run of your app.
This means that if you stop your application and re-run it,
you need to connect to DevTools again with the new URL.
Connect to a new app instance
If your app stops running
or you opened DevTools manually,
you should see a Connect dialog: | https://docs.flutter.dev/development/tools/devtools/cli/index.html |
24e0ff14b2ab-2 | You can manually connect DevTools to a new app instance
by copying the Observatory link you got from running your app,
such as http://127.0.0.1:52129/QjqebSY4lQ8=/
and pasting it into the connect dialog: | https://docs.flutter.dev/development/tools/devtools/cli/index.html |
e47c499845fd-0 | Using the CPU profiler view
Tools
DevTools
Using the CPU profiler view
What is it?
CPU Profiler
Profile granularity
Flame chart
Call tree
Bottom up
Other resources
Note:
The CPU profiler view works with Dart CLI and mobile apps only.
Use Chrome DevTools to analyze performance
of a web app.
What is it?
The CPU profiler view allows you to record and profile a
session from your Dart or Flutter application.
Note:
If you are running a Flutter application,
use a profile build to analyze performance.
CPU profiles are not indicative of release performance
unless your Flutter application is run in profile mode.
CPU Profiler | https://docs.flutter.dev/development/tools/devtools/cpu-profiler/index.html |
e47c499845fd-1 | CPU Profiler
Start recording a CPU profile by clicking Record.
When you are done recording, click Stop. At this point,
CPU profiling data is pulled from the VM and displayed
in the profiler views (Call Tree, Bottom Up, and Flame Chart).
Profile granularity
The default rate at which the VM collects CPU samples
is 1 sample / 250 μs. This is selected by default on
the CPU profiler view as “Profile granularity: medium”.
This rate can be modified using the selector at the top
of the page. The sampling rates for low, medium,
and high granularity are 1 / 1000 μs, 1 / 250 μs, and 1 / 50 μs,
respectively. It is important to know the trade-offs
of modifying this setting. | https://docs.flutter.dev/development/tools/devtools/cpu-profiler/index.html |
e47c499845fd-2 | A higher granularity profile has a higher sampling rate,
and therefore yields a fine-grained CPU profile with more samples.
This might also impact performance of your app since the VM
is being interrupted more often to collect samples. This also
causes the VM’s CPU sample buffer to overflow more quickly.
The VM has limited space where it can store CPU sample information.
At a higher sampling rate, the space fills up and begins
to overflow sooner than it would have if a lower sampling
rate was used. This means that you might not have access to CPU samples
from the beginning of the recorded profile.
A lower granularity profile has a lower sampling rate,
and therefore yields a coarse-grained CPU profile with fewer samples.
However, this impacts your app’s performance less.
The VM’s sample buffer also fills more slowly, so you can see
CPU samples for a longer period of app run time. This means that
you have a better chance of viewing CPU samples from the beginning
of the recorded profile.
Flame chart | https://docs.flutter.dev/development/tools/devtools/cpu-profiler/index.html |
e47c499845fd-3 | Flame chart
This tab of the profiler shows CPU samples for the recorded duration.
This chart should be viewed as a top-down stack trace, where the
top-most stack frame calls the one below it. The width of each stack
frame represents the amount of time it consumed the CPU. Stack frames
that consume a lot of CPU time might be a good place to look for possible
performance improvements.
Call tree
The call tree view shows the method trace for the CPU profile.
This table is a top-down representation of the profile,
meaning that a method can be expanded to show its callees.
Time the method spent executing its own code as well as
the code for its callees.
Time the method spent executing only its own code.
Name of the called method.
File path for the method call site.
Bottom up | https://docs.flutter.dev/development/tools/devtools/cpu-profiler/index.html |
e47c499845fd-4 | File path for the method call site.
Bottom up
The bottom up view shows the method trace for the CPU profile but,
as the name suggests, it’s a bottom-up representation of the profile.
This means that each top-level method in the table is actually the
last method in the call stack for a given CPU sample (in other words,
it’s the leaf node for the sample).
In this table, a method can be expanded to show its callers.
Time the method spent executing its own code
as well as the code for its callee. | https://docs.flutter.dev/development/tools/devtools/cpu-profiler/index.html |
e47c499845fd-5 | For top-level methods in the bottom-up tree
(leaf stack frames in the profile), this is the time the
method spent executing only its own code. For sub nodes
(the callers in the CPU profile), this is the self time
of the callee when being called by the caller.
In the following example, the self time of the caller
createRenderObject is equal to the self time of
the callee debugCheckHasDirectionality when being called by
the caller.
Name of the called method.
File path for the method call site.
Other resources
To learn how to use DevTools to analyze
the CPU usage of a compute-intensive Mandelbrot app,
check out a guided CPU Profiler View tutorial.
Also, learn how to analyze CPU usage when the app
uses isolates for parallel computing. | https://docs.flutter.dev/development/tools/devtools/cpu-profiler/index.html |
a80bc7878885-0 | Using the debugger
Tools
DevTools
Using the debugger
Getting started
Setting breakpoints
The call stack and variable areas
Stepping through source code
Console output
Breaking on exceptions
Known issues
Other resources
Note:
DevTools hides the Debugger tab if the app was launched
from VS Code because VS Code has a built-in debugger.
Getting started
DevTools includes a full source-level debugger, supporting
breakpoints, stepping, and variable inspection.
Note:
The debugger works with all Flutter and Dart applications.
If you are looking for a way to use GDB to remotely debug the
Flutter engine running within an Android app process,
check out flutter_gdb. | https://docs.flutter.dev/development/tools/devtools/debugger/index.html |
a80bc7878885-1 | When you open the debugger tab, you should see the source for the main
entry-point for your app loaded in the debugger.
In order to browse around more of your application sources, click Libraries
(top right) or use the hot key command ⌘ + P / ctrl + P. This will open the
libraries window and allow you to search for other source files.
Setting breakpoints
To set a breakpoint, click the left margin (the line number ruler)
in the source area. Clicking once sets a breakpoint, which should
also show up in the Breakpoints area on the left. Clicking
again removes the breakpoint.
The call stack and variable areas | https://docs.flutter.dev/development/tools/devtools/debugger/index.html |
a80bc7878885-2 | The call stack and variable areas
When your application encounters a breakpoint, it pauses there,
and the DevTools debugger shows the paused execution location
in the source area. In addition, the Call stack and Variables
areas populate with the current call stack for the paused isolate,
and the local variables for the selected frame. Selecting other
frames in the Call stack area changes the contents of the variables.
Within the Variables area, you can inspect individual objects by
toggling them open to see their fields. Hovering over an object
in the Variables area calls toString() for that object and
displays the result.
Stepping through source code
When paused, the three stepping buttons become active.
Use Step in to step into a method invocation, stopping at
the first executable line in that invoked method.
Use Step over to step over a method invocation;
this steps through source lines in the current method. | https://docs.flutter.dev/development/tools/devtools/debugger/index.html |
a80bc7878885-3 | Use Step out to step out of the current method,
without stopping at any intermediary lines.
In addition, the Resume button continues regular
execution of the application.
Console output
Console output for the running app (stdout and stderr) is
displayed in the console, below the source code area.
You can also see the output in the Logging view.
Breaking on exceptions
To adjust the stop-on-exceptions behavior, toggle the
Ignore dropdown at the top of the debugger view.
Breaking on unhandled excepts only pauses execution if the
breakpoint is considered uncaught by the application code.
Breaking on all exceptions causes the debugger to pause
whether or not the breakpoint was caught by application code.
Known issues
When performing a hot restart for a Flutter application,
user breakpoints are cleared.
Other resources
For more information on debugging and profiling, see the
Debugging page. | https://docs.flutter.dev/development/tools/devtools/debugger/index.html |
c9a3f90b4c33-0 | DevTools
Tools
DevTools
Topics:
Overview
Install from Android Studio & IntelliJ
Install from VS Code
Install from command line
Flutter inspector
Performance view
CPU Profiler view
Memory view
Network view
Debugger
Logging view
App size tool
Release notes | https://docs.flutter.dev/development/tools/devtools/index.html |
ff26818d7ee4-0 | Using the Flutter inspector
Tools
DevTools
Using the Flutter inspector
What is it?
Get started
Debugging layout issues visually
Inspecting a widget
Flutter Layout Explorer
Using the Layout Explorer
Flex layouts
Fixed size layouts
Visual debugging
Slow animations
See also
Show guidelines
Render boxes
Alignments
Padding
Scroll views
Clipping
Spacers
Show baselines
Highlight repaints
Highlight oversized images
Fixing images
More information
Details Tree
Track widget creation
Other resources
Note:
The inspector works with all Flutter applications.
What is it? | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-1 | What is it?
The Flutter widget inspector is a powerful tool for visualizing and
exploring Flutter widget trees. The Flutter framework uses widgets
as the core building block for anything from controls
(such as text, buttons, and toggles),
to layout (such as centering, padding, rows, and columns).
The inspector helps you visualize and explore Flutter widget
trees, and can be used for the following:
understanding existing layouts
diagnosing layout issues
Get started
To debug a layout issue, run the app in debug mode and
open the inspector by clicking the Flutter Inspector
tab on the DevTools toolbar.
Note:
You can still access the Flutter inspector directly from
Android Studio/IntelliJ, but you might prefer the
more spacious view when running it from DevTools
in a browser.
Debugging layout issues visually | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-2 | Debugging layout issues visually
The following is a guide to the features available in the
inspector’s toolbar. When space is limited, the icon is
used as the visual version of the label.
Enable this button in order to select
a widget on the device to inspect it. For more information,
see Inspecting a widget.
Reload the current widget info.
Slow animations
Run animations 5 times slower to help fine-tune them.
Show guidelines
Overlay guidelines to assist with fixing layout issues.
Show baselines
Show baselines, which are used for aligning text.
Can be useful for checking if text is aligned.
Highlight repaints
Show borders that change color when elements repaint.
Useful for finding unnecessary repaints.
Highlight oversized images | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-3 | Highlight oversized images
Highlights images that are using too much memory
by inverting colors and flipping them.
Inspecting a widget
You can browse the interactive widget tree to view nearby
widgets and see their field values.
To locate individual UI elements in the widget tree,
click the Select Widget Mode button in the toolbar.
This puts the app on the device into a “widget select” mode.
Click any widget in the app’s UI; this selects the widget on the
app’s screen, and scrolls the widget tree to the corresponding node.
Toggle the Select Widget Mode button again to exit
widget select mode.
When debugging layout issues, the key fields to look at are the
size and constraints fields. The constraints flow down the tree,
and the sizes flow back up. For more information on how this works,
see Understanding constraints.
Flutter Layout Explorer
The Flutter Layout Explorer helps you to better understand
Flutter layouts. | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-4 | The Flutter Layout Explorer helps you to better understand
Flutter layouts.
For an overview of what you can do with this tool, see
the Flutter Explorer video:
You might also find the following step-by-step article useful:
How to debug layout issues with the Flutter Inspector
Using the Layout Explorer
From the Flutter Inspector, select a widget. The Layout Explorer
supports both flex layouts and fixed size layouts, and has
specific tooling for both kinds.
Flex layouts
When you select a flex widget (for example, Row, Column, Flex)
or a direct child of a flex widget, the flex layout tool will
appear in the Layout Explorer. | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-5 | The Layout Explorer visualizes how Flex widgets and their
children are laid out. The explorer identifies the main axis
and cross axis, as well as the current alignment for each
(for example, start, end, and spaceBetween).
It also shows details like flex factor, flex fit, and layout
constraints.
Additionally, the explorer shows layout constraint violations
and render overflow errors. Violated layout constraints
are colored red, and overflow errors are presented in the
standard “yellow-tape” pattern, as you might see on a running
device. These visualizations aim to improve understanding of
why overflow errors occur as well as how to fix them.
Clicking a widget in the layout explorer mirrors
the selection on the on-device inspector. Select Widget Mode
needs to be enabled for this. To enable it,
click on the Select Widget Mode button in the inspector. | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-6 | For some properties, like flex factor, flex fit, and alignment,
you can modify the value via dropdown lists in the explorer.
When modifying a widget property, you see the new value reflected
not only in the Layout Explorer, but also on the
device running your Flutter app. The explorer animates
on property changes so that the effect of the change is clear.
Widget property changes made from the layout explorer don’t
modify your source code and are reverted on hot reload.
Interactive Properties
mainAxisAlignment,
crossAxisAlignment, and
FlexParentData.flex.
In the future, we may add support for additional properties
such as
mainAxisSize,
textDirection, and
FlexParentData.fit.
mainAxisAlignment
Supported values:
MainAxisAlignment.start
MainAxisAlignment.end
MainAxisAlignment.center | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-7 | MainAxisAlignment.end
MainAxisAlignment.center
MainAxisAlignment.spaceBetween
MainAxisAlignment.spaceAround
MainAxisAlignment.spaceEvenly
crossAxisAlignment
Supported values:
CrossAxisAlignment.start
CrossAxisAlignment.center
CrossAxisAlignment.end
CrossAxisAlignment.stretch
FlexParentData.flex
Layout Explorer supports 7 flex options in the UI
(null, 0, 1, 2, 3, 4, 5), but technically the flex
factor of a flex widget’s child can be any int.
Flexible.fit
Layout Explorer supports the two different types of
FlexFit: loose and tight.
Fixed size layouts | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-8 | Fixed size layouts
When you select a fixed size widget that is not a child
of a flex widget, fixed size layout information will appear
in the Layout Explorer. You can see size, constraint, and padding
information for both the selected widget and its nearest upstream
RenderObject.
Visual debugging
The Flutter Inspector provides several options for visually debugging your app.
These are the options available from the inspector within Flutter DevTools.
Slow animations
When enabled, this option runs animations 5 times slower for easier visual
inspection.
This can be useful if you want to carefully observe and tweak an animation that
doesn’t look quite right.
This can also be set in code:
This slows the animations by 5x.
See also
The following links provide more info.
Flutter documentation: timeDilation property
The following screen recordings show before and after slowing an animation. | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-9 | The following screen recordings show before and after slowing an animation.
Show guidelines
This feature draws guidelines over your app that display render boxes, alignments,
paddings, scroll views, clippings and spacers.
This tool can be used for better understanding your layout. For instance,
by finding unwanted padding or understanding widget alignment.
You can also enable this in code:
Render boxes
Widgets that draw to the screen create a render box, the
building blocks of Flutter layouts. They’re shown with a bright blue border:
Alignments
Alignments are shown with yellow arrows. These arrows show the vertical
and horizontal offsets of a widget relative to its parent.
For example, this button’s icon is shown as being centered by the four arrows:
Padding
Padding is shown with a semi-transparent blue background:
Scroll views | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-10 | Scroll views
Widgets with scrolling contents (such as list views) are shown with green arrows:
Clipping
Clipping, for example when using the ClipRect widget, are shown
with a dashed pink line with a scissors icon:
Spacers
Spacer widgets are shown with a grey background,
such as this SizedBox without a child:
Show baselines
This option makes all baselines visible.
Baselines are horizontal lines used to position text.
This can be useful for checking whether text is precisely aligned vertically.
For example, the text baselines in the following screenshot are slightly misaligned:
The Baseline widget can be used to adjust baselines.
A line is drawn on any render box that has a baseline set;
alphabetic baselines are shown as green and ideographic as yellow.
You can also enable this in code:
Highlight repaints | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-11 | You can also enable this in code:
Highlight repaints
This option draws a border around all render boxes
that changes color every time that box repaints.
This rotating rainbow of colors is useful for finding parts of your app
that are repainting too often and potentially harming performance.
For example, one small animation could be causing an entire page
to repaint on every frame.
Wrapping the animation in a RepaintBoundary widget limits
the repainting to just the animation.
Here the progress indicator causes its container to repaint:
Wrapping the progress indicator in a RepaintBoundary causes
only that section of the screen to repaint:
RepaintBoundary widgets have tradeoffs. They can help with performance,
but they also have an overhead of creating a new canvas,
which uses additional memory.
You can also enable this option in code:
Highlight oversized images | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-12 | Highlight oversized images
This option highlights images that are too large by both inverting their colors
and flipping them vertically:
The highlighted images use more memory than is required;
for example, a large 5MB image displayed at 100 by 100 pixels.
Such images can cause poor performance, especially on lower-end devices
and when you have many images, as in a list view,
this performance hit can add up.
Information about each image is printed in the debug console:
dash.png has a display size of 213×392 but a decode size of 2130×392, which uses an additional 2542KB.
Images are deemed too large if they use at least 128KB more than required.
Fixing images
Wherever possible, the best way to fix this problem is resizing
the image asset file so it’s smaller. | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-13 | If this isn’t possible, you can use the cacheHeight and cacheWidth
parameters on the Image constructor:
This makes the engine decode this image at the specified size,
and reduces memory usage (decoding and storage is still more expensive
than if the image asset itself was shrunk).
The image is rendered to the constraints of the layout or width and height
regardless of these parameters.
This property can also be set in code:
More information
You can learn more at the following link:
Flutter documentation: debugInvertOversizedImages
Details Tree
Select the Details Tree tab to display the details tree for the
selected widget.
From the details tree, you can gather useful information about a
widget’s properties, render object, and children.
Track widget creation | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-14 | Track widget creation
Part of the functionality of the Flutter inspector is based on
instrumenting the application code in order to better understand
the source locations where widgets are created. The source
instrumentation allows the Flutter inspector to present the
widget tree in a manner similar to how the UI was defined
in your source code. Without it, the tree of nodes in the
widget tree are much deeper, and it can be more difficult to
understand how the runtime widget hierarchy corresponds to
your application’s UI.
You can disable this feature by passing --no-track-widget-creation to
the flutter run command.
Here are examples of what your widget tree might look like
with and without track widget creation enabled.
Track widget creation enabled (default):
Track widget creation disabled (not recommended):
This feature prevents otherwise-identical const Widgets from
being considered equal in debug builds. For more details, see
the discussion on common problems when debugging.
Other resources | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
ff26818d7ee4-15 | Other resources
For a demonstration of what’s generally possible with the inspector,
see the DartConf 2018 talk demonstrating the IntelliJ version
of the Flutter inspector.
To learn how to visually debug layout issues
using DevTools, check out a guided
Flutter Inspector tutorial. | https://docs.flutter.dev/development/tools/devtools/inspector/index.html |
417ea4dcb22f-0 | Using the Logging view
Tools
DevTools
Using the Logging view
What is it?
Standard logging events
Logging from your application
Clearing logs
Other resources
Note:
The logging view works with all Flutter and Dart applications.
What is it?
The logging view displays events from the Dart runtime,
application frameworks (like Flutter), and application-level
logging events.
Standard logging events
By default, the logging view shows:
Garbage collection events from the Dart runtime
Flutter framework events, like frame creation events
stdout and stderr from applications
Custom logging events from applications
Logging from your application
To implement logging in your code,
see the Logging section in the
Debugging Flutter apps programmatically
page. | https://docs.flutter.dev/development/tools/devtools/logging/index.html |
417ea4dcb22f-1 | Clearing logs
To clear the log entries in the logging view,
click the Clear logs button.
Other resources
To learn about different methods of logging
and how to effectively use DevTools to
analyze and debug Flutter apps faster,
check out a guided Logging View tutorial. | https://docs.flutter.dev/development/tools/devtools/logging/index.html |
7858082a132f-0 | Using the Memory view
Tools
DevTools
Using the Memory view
Reasons to use the memory view
Basic memory concepts
Root object, retaining path, and reachability
Root object
Reachability
Retaining path
Example
Shallow size vs retained size
Dart size vs external (native) size
Memory leaks happen in Dart?
Why garbage collector cannot prevent all leaks?
Why closures require extra attention
Why BuildContext requires extra attention
How to fix leak prone code?
General rule for BuildContext
Memory leak vs memory bloat
Memory view guide
Expandable chart
Memory anatomy
Memory overview chart
Profile tab
Diff tab
Trace tab
Bottom up vs call tree view
Other resources | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-1 | Bottom up vs call tree view
Other resources
The memory view provides insights into details
of the application’s memory allocation and
tools to detect and debug specific issues.
For information on how to locate DevTools screens in different IDEs,
check out the DevTools overview.
To better understand the insights found on this page,
the first section explains how Dart manages memory.
If you already understand Dart’s memory management,
you can skip to the Memory view guide.
Reasons to use the memory view
Use the memory view for preemptive memory optimization or when
your application experiences one of the following conditions:
Crashes when it runs out of memory
Slows down
Causes the device to slow down or become unresponsive
Shuts down because it exceeded the memory limit, enforced by operating system | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-2 | Shuts down because it exceeded the memory limit, enforced by operating system
Exceeds memory usage limit
This limit can vary depending on the type of devices your app targets.
Suspect a memory leak
Basic memory concepts
Dart objects created using a class constructor
(for example, by using MyClass()) live in a
portion of memory called the heap. The memory
in the heap is managed by the Dart VM (virtual machine).
The Dart VM allocates memory for the object at the moment of the object creation,
and releases (or deallocates) the memory when the object
is no longer used (see Dart garbage collection).
Root object, retaining path, and reachability
Root object
Every Dart application creates a root object that references,
directly or indirectly, all other objects the application allocates.
Reachability | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-3 | Reachability
If, at some moment of the application run,
the root object stops referencing an allocated object,
the object becomes unreachable,
which is a signal for the garbage collector (GC)
to deallocate the object’s memory.
Retaining path
The sequence of references from root to an object
is called the object’s retaining path,
as it retains the object’s memory from the garbage collection.
One object can have many retaining paths.
Objects with at least one retaining path are
called reachable objects.
Example
The following example illustrates the concepts:
class
Child
{}
class
Parent
Child
child
Parent
parent1
Parent
();
void
myFunction
()
Child | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-4 | myFunction
()
Child
child
Child
();
// The `child` object was allocated in memory.
// It's now retained from garbage collection
// by one retaining path (root …-> myFunction -> child).
Parent
parent2
Parent
().
child
child
parent1
child
child
// At this point the `child` object has three retaining paths:
// root …-> myFunction -> child
// root …-> myFunction -> parent2 -> child
// root -> parent1 -> child
child
null
parent1
child
null
parent2
null | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-5 | null
parent2
null
// At this point, the `child` instance is unreachable
// and will eventually be garbage collected.
Shallow size vs retained size
Shallow size includes only the size of the object
and its references, while retained size also includes
the size of the retained objects.
The retained size of the root object includes
all reachable Dart objects.
In the following example, the size of myHugeInstance
isn’t part of the parent’s or child’s shallow sizes,
but is part of their retained sizes:
class
Child
/// The instance is part of both [parent] and [parent.child]
/// retained sizes.
final
myHugeInstance
MyHugeInstance
();
class
Parent
Child | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-6 | ();
class
Parent
Child
child
Parent
parent
Parent
().
child
Child
();
In DevTools calculations, if an object has more
than one retaining path, its size is assigned as
retained only to the members of the shortest retaining path.
In this example the object x has two retaining paths:
root ->
a -> b -> c -> x
root ->
d -> e -> x
(shortest retaining path to
`x
Only members of the shortest path (d and e) will include
x into their retaining size.
Dart size vs external (native) size | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-7 | Dart size vs external (native) size
Some parts of an object (for example, graphics)
might be stored outside of Dart heap,
in native device memory.
You can observe an object’s Dart heap, external,
and total memory allocation breakdown on the Profile tab:
Memory leaks happen in Dart?
Garbage collector cannot prevent all types of memory leaks, and developers
still need to watch objects to have leak-free lifecycle.
Why garbage collector cannot prevent all leaks?
While the garbage collector takes care of all
unreachable objects, it’s the responsibility
of the application to ensure that unneeded objects
are no longer reachable (referenced from the root). | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-8 | So, if non needed objects are left referenced
(in a global or static variable,
or as a field of a long-living object),
the garbage collector can’t recognize them,
the memory allocation grows progressively,
and the app eventually crashes with an out-of-memory error.
Why closures require extra attention
One hard-to-catch leak pattern relates to using closures.
In the following code, a reference to the
designed-to-be short-living myHugeObject is implicitly
stored in the closure context and passed to setHandler.
As a result, myHugeObject won’t be garbage collected
as long as handler is reachable.
final
handler
()
print
myHugeObject
name
);
setHandler
handler
);
Why BuildContext requires extra attention | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-9 | handler
);
Why BuildContext requires extra attention
An example of a large, short-living object that
might squeeze into a long-living area and thus cause leaks,
is the context parameter passed to Flutter’s
build method.
The following code is leak prone,
as useHandler might store the handler
in a long-living area:
// BAD: DO NOT DO THIS
// This code is leak prone:
@override
Widget
build
BuildContext
context
final
handler
()
apply
Theme
of
context
));
useHandler
handler
);
How to fix leak prone code? | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-10 | );
How to fix leak prone code?
The following code is not leak prone,
because:
The closure doesn’t use the large and short-living context object.
The theme object (used instead) is long-living. It is created once and
shared between BuildContext instances.
// GOOD
@override
Widget
build
BuildContext
context
final
theme
Theme
of
context
);
final
handler
()
apply
theme
);
useHandler
handler
);
General rule for BuildContext | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-11 | handler
);
General rule for BuildContext
In general, use the following rule for a
BuildContext: if the closure doesn’t outlive
the widget, it’s ok to pass the context to the closure.
Stateful widgets require extra attention.
They consist of two classes: the widget and the
widget state,
where the widget is short living,
and the state is long living. The build context,
owned by the widget, should never be referenced
from the state’s fields, as the state won’t be garbage
collected together with the widget, and can significantly outlive it.
Memory leak vs memory bloat
In a memory leak, an application progressively uses memory,
for example, by repeatedly creating a listener,
but not disposing it.
Memory bloat uses more memory than is necessary for
optimal performance, for example, by using overly large
images or keeping streams open through their lifetime. | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-12 | Both leaks and bloats, when large,
cause an application to crash with an out-of-memory error.
However, leaks are more likely to cause memory issues,
because even a small leak,
if repeated many times, leads to a crash.
Memory view guide
The DevTools memory view helps you investigate
memory allocations (both in the heap and external),
memory leaks, memory bloat, and more. The view
has the following features:
Expandable chart
Get a high-level trace of memory allocation,
and view both standard events (like garbage collection)
and custom events (like image allocation).
Profile tab
See current memory allocation listed by class and
memory type (Dart or external/native).
Diff tab
Detect and investigate a feature’s memory management issues.
Trace tab
Investigate a feature’s memory management for
a specified set of classes.
Expandable chart | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-13 | Expandable chart
The expandable chart provides the following features:
Memory anatomy
A timeseries graph visualizes the state of
Flutter memory at successive intervals of time.
Each data point on the chart corresponds to the
timestamp (x-axis) of measured quantities (y-axis)
of the heap. For example, usage, capacity, external,
garbage collection, and resident set size are captured.
Memory overview chart
The memory overview chart is a timeseries graph
of collected memory statistics. It visually presents
the state of the Dart or Flutter heap and Dart’s
or Flutter’s native memory over time. | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-14 | The chart’s x-axis is a timeline of events (timeseries).
The data plotted in the y-axis all has a timestamp of
when the data was collected. In other words,
it shows the polled state (capacity, used, external,
RSS (resident set size), and GC (garbage collection))
of the memory every 500 ms. This helps provide a live
appearance on the state of the memory as the application is running.
Clicking the Legend button displays the
collected measurements, symbols, and colors
used to display the data.
The Memory Size Scale y-axis automatically
adjusts to the range of data collected in the
current visible chart range.
The quantities plotted on the y-axis are as follows:
Objects (Dart and Flutter objects) in the heap. | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-15 | Objects (Dart and Flutter objects) in the heap.
Memory that isn’t in the Dart/Flutter heap
but is still part of the total memory footprint.
Objects in this memory would be native objects
(for example, from reading a file into memory,
or a decoded image). The native objects are exposed
to the Dart VM from the native OS (such as Android,
Linux, Windows, iOS) using a Dart embedder.
The embedder creates a Dart wrapper with a finalizer,
allowing Dart code to communicate with these native resources.
Flutter has an embedder for Android and iOS.
For more information, see Command-line and server apps,
Dart on the server with Dart Frog,
Custom Flutter Engine Embedders,
Dart web server deployment with Heroku.
The timestamps of all collected memory statistics
and events at a particular point in time (timestamp). | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-16 | The size of the Flutter engine’s raster cache
layer(s) or picture(s), while performing the
final rendering after compositing.
For more information, see the
Flutter architectural overview
and DevTools Performance view.
The current capacity of the heap is typically
slightly larger than the total size of all heap objects.
The resident set size displays the amount of memory
for a process.
It doesn’t include memory that is swapped out.
It includes memory from shared libraries that are
loaded, as well as all stack and heap memory.
For more information, see Dart VM internals.
Profile tab
Use the Profile tab to see current memory
allocation by class and memory type. For a
deeper analysis in Google Sheets or other tools,
download the data in CSV format.
Toggle Refresh on GC, to see allocation in real time.
Diff tab | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-17 | Diff tab
Use the Diff tab to investigate a feature’s
memory management. Follow the guidance on the tab
to take snapshots before and after interaction
with the application, and diff the snapshots:
Tap the Filter classes and packages button,
to narrow the data:
For a deeper analysis in Google Sheets
or other tools, download the data in CSV format.
Trace tab
Use the Trace tab to investigate what methods
allocate memory for a set of classes
during feature execution:
Select classes to trace
Interact with your app to trigger the code
you are interested in
Tap Refresh
Select a traced class
Review the collected data
Bottom up vs call tree view
Switch between bottom-up and call tree views
depending on specifics of your tasks. | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
7858082a132f-18 | Switch between bottom-up and call tree views
depending on specifics of your tasks.
The call tree view shows the method allocations
for each instance. The view is a top-down representation
of the call stack, meaning that a method can be expanded
to show its callees.
The bottom-up view shows the list of different
call stacks that have allocated the instances.
Other resources
To learn how to monitor an app’s memory usage
and detect memory leaks using DevTools,
check out a guided Memory View tutorial. | https://docs.flutter.dev/development/tools/devtools/memory/index.html |
1cb935927a69-0 | Using the Network View
Tools
DevTools
Using the Network View
What is it?
How to use it
Search and filtering
Other resources
Note:
The network view works with all Flutter and Dart applications.
What is it?
The network view allows you to inspect HTTP, HTTPS, and web socket traffic from
your Dart or Flutter application.
How to use it
Network traffic should be recording by default when you open the Network page.
If it is not, click the Record network traffic button in the upper left to
begin polling.
Select a network request from the table (left) to view details (right). You can
inspect general and timing information about the request, as well as the content
of response and request headers and bodies.
Search and filtering | https://docs.flutter.dev/development/tools/devtools/network/index.html |
1cb935927a69-1 | Search and filtering
You can use the search and filter controls to find a specific request or filter
requests out of the request table.
To apply a filter, press the filter button (right of the search bar). You will
see a filter dialog pop up:
The filter query syntax is described in the dialog. You can filter network
requests by the following keys:
method, m: this filter corresponds to the value in the “Method” column
status, s: this filter corresponds to the value in the “Status” column
type, t: this filter corresponds to the value in the “Type” column
Any text that is not paired with an available filter key will be queried against
all categories (method, uri, status, type).
Example filter queries:
Other resources | https://docs.flutter.dev/development/tools/devtools/network/index.html |
1cb935927a69-2 | Example filter queries:
Other resources
HTTP and HTTPs requests are also surfaced in the Timeline as
asynchronous timeline events. Viewing network activity in the timeline can be
useful if you want to see how HTTP traffic aligns with other events happening
in your app or in the Flutter framework.
To learn how to monitor an app’s network traffic and inspect
different types of requests using the DevTools,
check out a guided Network View tutorial.
The tutorial also uses the view to identify network activity that
causes poor app performance. | https://docs.flutter.dev/development/tools/devtools/network/index.html |
65d7c243f438-0 | DevTools
Tools
DevTools
DevTools
What is DevTools?
What can I do with DevTools?
How do I install DevTools?
Providing feedback
Other resources
What is DevTools?
DevTools is a suite of performance and debugging tools
for Dart and Flutter.
What can I do with DevTools?
Here are some of the things you can do with DevTools:
Inspect the UI layout and state of a Flutter app.
Diagnose UI jank performance issues in a Flutter app.
CPU profiling for a Flutter or Dart app.
Network profiling for a Flutter app.
Source-level debugging of a Flutter or Dart app.
Debug memory issues in a Flutter or Dart
command-line app. | https://docs.flutter.dev/development/tools/devtools/overview/index.html |
65d7c243f438-1 | Debug memory issues in a Flutter or Dart
command-line app.
View general log and diagnostics information
about a running Flutter or Dart
command-line app.
Analyze code and app size.
We expect you to use DevTools in conjunction with
your existing IDE or command-line based development workflow.
How do I install DevTools?
See the Android Studio/IntelliJ, VS Code, or
command line pages for installation instructions.
Providing feedback
Please give DevTools a try, provide feedback, and file issues
in the DevTools issue tracker. Thanks!
Other resources
For more information on debugging and profiling
Flutter apps, see the Debugging page and,
in particular, its list of other resources.
For more information on using DevTools with Dart command-line apps, see the
DevTools documentation on dart.dev. | https://docs.flutter.dev/development/tools/devtools/overview/index.html |
47922abbc705-0 | Using the Performance view
Tools
DevTools
Using the Performance view
Basic performance concepts
What is the Performance view?
What is a frame in Flutter?
Flutter frames chart
UI
Raster
Jank (slow frame)
Shader compilation
Timeline events chart
Enhance tracing
Track widget builds
Track layouts
Track paints
More debugging options
Import and export
Other resources
Note:
The performance view works with Dart CLI and mobile apps only.
Use Chrome DevTools to generate timeline events
for a web app.
Basic performance concepts
What is the Performance view?
The performance view offers timing and performance information for activity in
your application. It consists of three parts, each increasing in granularity.
Flutter frames chart (Flutter apps only) | https://docs.flutter.dev/development/tools/devtools/performance/index.html |
47922abbc705-1 | Flutter frames chart (Flutter apps only)
Timeline events chart
CPU profiler
Use a profile build of your application to analyze performance.
Frame rendering times aren’t indicative of release performance
when running in debug mode. Run your app in profile mode,
which still preserves useful debugging information.
The performance view also supports importing and exporting of
data snapshots. For more information,
check out the Import and export section.
What is a frame in Flutter?
Flutter is designed to render its UI at 60 frames per second
(fps), or 120 fps on devices capable of 120Hz updates.
Each render is called a frame.
This means that, approximately every 16ms, the UI updates
to reflect animations or other changes to the UI. A frame
that takes longer than 16ms to render causes jank
(jerky motion) on the display device.
Flutter frames chart | https://docs.flutter.dev/development/tools/devtools/performance/index.html |
47922abbc705-2 | Flutter frames chart
This chart contains Flutter frame information for your application.
Each bar set in the chart represents a single Flutter frame.
The bars are color-coded to highlight the different portions
of work that occur when rendering a Flutter frame: work from
the UI thread and work from the raster thread (previously known
as the GPU thread).
Selecting a bar from this chart centers the flame chart below on the timeline
events corresponding to the selected Flutter frame.
The events are highlighted with blue brackets.
UI
The UI thread executes Dart code in the Dart VM. This includes
code from your application as well as the Flutter framework.
When your app creates and displays a scene, the UI thread creates
a layer tree, a lightweight object containing device-agnostic
painting commands, and sends the layer tree to the raster thread
to be rendered on the device. Do not block this thread.
Raster | https://docs.flutter.dev/development/tools/devtools/performance/index.html |
47922abbc705-3 | Raster
The raster thread (previously known as the GPU thread) executes
graphics code from the Flutter Engine.
This thread takes the layer tree and displays it by talking to
the GPU (graphic processing unit). You cannot directly access
the raster thread or its data, but if this thread is slow, it’s a
result of something you’ve done in the Dart code. Skia, the
graphics library, runs on this thread.
Sometimes a scene results in a layer tree that is easy to construct,
but expensive to render on the raster thread. In this case, you
need to figure out what your code is doing that is causing
rendering code to be slow. Specific kinds of workloads are more
difficult for the GPU. They might involve unnecessary calls to
saveLayer(), intersecting opacities with multiple objects,
and clips or shadows in specific situations.
For more information on profiling, check out
Identifying problems in the GPU graph.
Jank (slow frame) | https://docs.flutter.dev/development/tools/devtools/performance/index.html |
47922abbc705-4 | Jank (slow frame)
The frame rendering chart shows jank with a red overlay.
A frame is considered to be janky if it takes more than
~16 ms to complete (for 60 FPS devices). To achieve a frame rendering rate of
60 FPS (frames per second), each frame must render in
~16 ms or less. When this target is missed, you may
experience UI jank or dropped frames.
For more information on how to analyze your app’s performance,
check out Flutter performance profiling.
Shader compilation
Shader compilation occurs when a shader is first used in your Flutter
app. Frames that perform shader compilation are marked in dark
red:
For more information on how to reduce shader compilation jank,
check out Reduce shader compilation jank on mobile.
Timeline events chart | https://docs.flutter.dev/development/tools/devtools/performance/index.html |
47922abbc705-5 | Timeline events chart
The timeline events chart shows all event tracing from your application.
The Flutter framework emits timeline events as it works to build frames,
draw scenes, and track other activity such as HTTP traffic.
These events show up here in the Timeline.
You can also send your own Timeline events using the dart:developer
Timeline
and TimelineTask
APIs.
The flame chart supports zooming and panning:
To zoom, scroll up and down with the mouse wheel / trackpad
To pan horizontally, either click and drag the chart or
scroll horizontally with the mouse wheel / trackpad
To pan vertically, either click and drag the chart or use
alt + scroll
The WASD keys also work for controlling zoom and horizontal scroll position
You can click an event to view CPU profiling information in the CPU profiler
below, described in the next section.
Enhance tracing | https://docs.flutter.dev/development/tools/devtools/performance/index.html |
Subsets and Splits