Sub topic 12
A Repeatable Workflow from Symptom to Verified Fix
Assume that you know basic Dart syntax and asynchronous programming. You should also be able to build a simple Flutter app, run it on a device or emulator, and understand the widget tree and build method.
Flutter DevTools works best when you treat debugging as an investigation. Start with a visible symptom. Choose a tool that can measure that symptom. Form a small hypothesis, change one thing, and verify the result with the same measurement.
Start with the symptom
Do not open every DevTools tab at once. First describe what you can observe:
- A widget is missing or has the wrong properties.
- Text or another child overflows its parent.
- A button produces the wrong result.
- A screen freezes or animations stutter.
- Memory use keeps increasing after leaving a screen.
- A request returns an unexpected response.
- The release build is larger than expected.
The symptom determines the first tool to use.
| Symptom | First tool | Evidence to collect |
|---|---|---|
| Wrong widget or property | Widget Inspector | Widget hierarchy and properties |
| Overflow or incorrect size | Layout Explorer | Constraints and allocated space |
| Wrong value or code path | Logging or Debugger | Variable values and execution path |
| Stutter or slow interaction | Performance view | Frame times and expensive events |
| Growing memory use | Memory view | Allocation and disposal patterns |
| Unexpected HTTP result | Network view | URL, method, status, and timing |
| Large application package | App Size tool | Size by asset, package, and symbol |
Use the right run mode
Run mode changes the evidence you see.
- Debug mode supports breakpoints, assertions, and fast iteration. Its timing does not represent production performance.
- Profile mode disables most debugging overhead while keeping performance and memory tools useful. Use it on a physical device when investigating jank or memory behavior.
- Release mode represents the shipped application. It is useful for confirming production behavior, but interactive debugging features are limited.
Connect DevTools to the same running process that shows the problem.
# Use debug mode for layout and logic investigation.
flutter run
# Use profile mode for performance and memory investigation.
flutter run --profile
# Start DevTools separately if needed.
dart devtoolsIf the problem appears only in one mode, record that fact. A layout error that exists in debug mode is different from a frame-time problem caused by debug overhead.
Follow a hypothesis
Use this sequence for each investigation:
- Reproduce the problem with clear steps.
- Record a baseline, such as the overflowing widget, frame time, memory usage, or response status.
- State a hypothesis. For example, “The
Rowgives the message unbounded width.” - Use one DevTools view to test that hypothesis.
- Make the smallest suitable code change.
- Repeat the same steps and collect the same measurement.
- Check nearby behavior, such as another screen or a second request.
For a layout problem, inspect the widget tree first. Select the affected widget and open the Layout Explorer. Examine the constraints flowing into the widget and the space it receives. For example, a long message inside a Row may need a flex constraint:
Row(
children: [
const Icon(Icons.info),
Expanded(
child: Text(
'A very long message that must fit on a narrow screen.',
),
),
],
)Do not assume that removing the overflow warning proves the layout is correct. Check narrow and wide screens, long translations, text scaling, and different device orientations.
Match evidence to the problem
For logic problems, add a temporary structured log or pause at a conditional breakpoint. Include identifiers and values that explain the decision, not just a message such as “failed.”
import 'dart:developer' as developer;
void loadCart(List<String> items) {
developer.log(
'Loaded ${items.length} items',
name: 'cart',
);
}Use the Logging view to filter messages by name. Remove noisy diagnostic logs or lower their frequency before shipping.
For performance, record a trace in the Performance view. Look for frames that exceed the device’s frame budget and inspect the events inside those frames. Use the CPU Profiler when you need to identify which functions consume CPU time. Test in profile mode, because debug-mode timings can mislead you.
For memory, take a baseline snapshot, perform the navigation or action repeatedly, then take another snapshot. A screen that is correctly disposed should not leave continuously growing numbers of controllers, states, or other objects. Check lifecycle methods such as dispose, and then repeat the test after the fix.
For requests, use the Network view to compare the actual URL, method, headers, payload, status code, and duration with what the application expects. For build size, use the App Size tool and compare the largest assets, packages, and compiled sections before changing dependencies.
Make the result reproducible
Write down the device, operating system, Flutter version, run mode, test data, and exact reproduction steps. Without these details, a later comparison may use different conditions.
Exercise
A screen stutters only on a physical device, and memory grows after repeatedly opening and closing it. Which run mode and tools should you use first?
Show answer
Use profile mode. Record frame behavior in the Performance view, inspect CPU work with the CPU Profiler if needed, and compare memory snapshots in the Memory view. Verify the fix by repeating the same navigation cycle and measurements.