Sub topic 1
Launching and Connecting DevTools
Flutter DevTools is a set of debugging and performance tools that connects to a running Flutter application. It communicates with the Dart virtual machine through a VM service. The VM service exposes information such as the widget tree, logs, memory, and frame timing.
This chapter assumes that you know basic Dart syntax, can build simple Flutter widgets, and can run an app on an emulator, simulator, or physical device.
Prerequisites
Before starting, make sure that:
- Flutter is installed and available through the
fluttercommand. - Dart is available through the
dartcommand. - A Flutter project exists.
- An emulator, simulator, or physical device is running.
- The app can start without build errors.
- You understand the difference between a widget and the widget tree.
Start the Flutter App
Open a terminal in your Flutter project and start the app:
flutter runFlutter prints information about the selected device and the running application. It also starts a VM service for debugging. The output usually contains a URI similar to this:
The Flutter DevTools debugger and profiler on Pixel 8 is available at:
http://127.0.0.1:9100/...The exact port and URI change each time. Treat the printed URI as the connection address for this run.
You can also start the app in profile mode:
# Run the app in profile mode on a connected device
flutter run --profile
# Start DevTools on its own, then connect using the VM service URI printed by flutter run
dart devtoolsProfile mode is useful for measuring performance because it removes much of the extra checking used by debug mode while keeping the VM service available. Use debug mode for normal code investigation and profile mode for realistic performance measurements. Release mode is optimized for distribution and usually does not provide the same development connection.
Open DevTools
There are several ways to open DevTools:
- In supported IDEs, use the Flutter or Dart DevTools command while the app is running.
- Run
dart devtoolsin a separate terminal. This starts a local DevTools server and prints a browser address. - Open the DevTools URL printed by
flutter runwhen your Flutter installation provides a direct link.
When DevTools opens, select the running application or paste its VM service URI into the connection field. The browser page should show the application name, Dart version, Flutter version, and available tool tabs.
A successful connection has two parts:
- DevTools itself is running.
- DevTools is connected to the VM service for the correct application.
Starting the browser page alone does not connect it to an app.
Confirm the Connection
After connecting, check that the application name and device match the app you intended to inspect. This matters when several emulators or Flutter projects are running.
The connection can fail for several common reasons:
| Symptom | Likely cause | Action |
|---|---|---|
| No app appears | The app is not running with a VM service | Start it with `flutter run` |
| The URI no longer works | The app stopped or restarted | Copy the newest URI |
| DevTools cannot connect | A local port or network process is blocked | Restart DevTools and the app |
| The wrong app is shown | Multiple apps are running | Check the device and application name |
| Tools are missing | The app is running in an unsuitable mode | Use debug or profile mode |
Keep the terminal running while you use DevTools. Stopping flutter run normally stops the application and its VM service, so DevTools loses its connection. Hot reload usually keeps the same connection, although a full restart can briefly disconnect the page.
Exercise
Exercise
Start a Flutter app, open DevTools with dart devtools, and connect to the VM service URI printed by flutter run. Which application name and device does DevTools display?
Show answer
It should display the application currently running from your project and the device selected by flutter run. If it does not, restart the app and use the newest VM service URI.