Sub topic 1
Launching and connecting DevTools
Prerequisites
This chapter assumes you know basic Dart syntax, can build a simple Flutter app with StatelessWidget, can run an app on an emulator, simulator, or device, and understand the widget tree and its build method.
Launching and connecting DevTools
Flutter DevTools is a suite of debugging and performance tools that runs in your browser. Start your app in profile mode, then start DevTools from the command line:
flutter run --profile
dart devtoolsWhen the app starts, the terminal prints a VM service URI. Paste that URI into the DevTools connect field if DevTools does not connect on its own.
Choosing debug, profile, or release mode
Flutter builds an app in one of three modes. Pick the mode that matches the problem you are investigating.
| Mode | Best for | DevTools connects |
|---|---|---|
| Debug | Logic errors and widget inspection | Yes |
| Profile | Jank, CPU, and memory measurements | Yes |
| Release | Confirming the shipped build behaves correctly | No |
Debug mode adds checks that slow the app, so its timings are not reliable. Release mode turns off the debugging service, so DevTools cannot attach.
> Note: the diagram above uses a standard Mermaid flowchart.
Exploring the widget tree with the Widget Inspector
The Widget Inspector shows every widget in your running app as a tree. Select a widget in the tree, and the app highlights it on the device. The details panel shows the widget's size and constraints. For Row and Column widgets, the Layout Explorer shows how each child uses the available space.
Run this app in debug mode, then open the Inspector:
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: Home()));
class Home extends StatelessWidget {
const Home({super.key});
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: Text('Hello, Inspector'),
),
);
}
}Exercise
Which run mode should you use to measure frame timing, and why?
Show answer
Profile mode. It runs close to release speed and still lets DevTools connect. Debug mode adds checks that slow each frame, so its timings mislead.