Debugging Flutter apps programmatically

This doc describes debugging features that you can enable in code. For a full list of debugging and profiling tools, see the Debugging page.

Logging

You have two options for logging for your application. The first is to use stdout and stderr. Generally, this is done using print() statements, or by importing dart:io and invoking methods on stderr and stdout. For example:

stderr.writeln('print me');

If you output too much at once, then Android sometimes discards some log lines. To avoid this, use debugPrint(), from Flutter’s foundation library. This is a wrapper around print that throttles the output to a level that avoids being dropped by Android’s kernel.

The other option for application logging is to use the dart:developer log() function. This allows you to include a bit more granularity and information in the logging output. Here’s an example:

import 'dart:developer' as developer;

void main() {
  developer.log('log me', name: 'my.app.category');

  developer.log('log me 1', name: 'my.other.category');
  developer.log('log me 2', name: 'my.other.category');
}

You can also pass application data to the log call. The convention for this is to use the error: named parameter on the log() call, JSON encode the object you want to send, and pass the encoded string to the error parameter.

import 'dart:convert';
import 'dart:developer' as developer;

void main() {
  var myCustomObject = ...;

  developer.log(
    'log me',
    name: 'my.app.category',
    error: jsonEncode(myCustomObject),
  );
}

If viewing the logging output in DevTool’s logging view, the JSON encoded error param is interpreted as a data object and rendered in the details view for that log entry.

Setting breakpoints

You can insert programmatic breakpoints using the debugger() statement. To use this, you have to import the dart:developer package at the top of the relevant file.

The debugger() statement takes an optional when argument that you can specify to only break when a certain condition is true, as in the following example:

import 'dart:developer';

void someFunction(double offset) {
  debugger(when: offset > 30.0);
  // ...
}

Debug flags: application layers

Each layer of the Flutter framework provides a function to dump its current state or events to the console (using debugPrint).

Widget tree

To dump the state of the Widgets library, call debugDumpApp(). You can call this more or less any time that the application is not in the middle of running a build phase (in other words, not anywhere inside a build() method), if the app has built at least once and is in debug mode (in other words, any time after calling runApp()).

For example, the following application:

import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: AppHome(),
    ),
  );
}

class AppHome extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Material(
      child: Center(
        child: TextButton(
          onPressed: () {
            debugDumpApp();
          },
          child: Text('Dump App'),
        ),
      ),
    );
  }
}

The previous app outputs something like the following (the precise details vary by the version of the framework, the size of the device, and so forth):

I/flutter ( 6559): WidgetsFlutterBinding - CHECKED MODE
I/flutter ( 6559): RenderObjectToWidgetAdapter<RenderBox>([GlobalObjectKey RenderView(497039273)]; renderObject: RenderView)
I/flutter ( 6559): β””MaterialApp(state: _MaterialAppState(1009803148))
I/flutter ( 6559):  β””ScrollConfiguration()
I/flutter ( 6559):   β””AnimatedTheme(duration: 200ms; state: _AnimatedThemeState(543295893; ticker inactive; ThemeDataTween(ThemeData(Brightness.light Color(0xff2196f3) etc...) β†’ null)))
I/flutter ( 6559):    β””Theme(ThemeData(Brightness.light Color(0xff2196f3) etc...))
I/flutter ( 6559):     β””WidgetsApp([GlobalObjectKey _MaterialAppState(1009803148)]; state: _WidgetsAppState(552902158))
I/flutter ( 6559):      β””CheckedModeBanner()
I/flutter ( 6559):       β””Banner()
I/flutter ( 6559):        β””CustomPaint(renderObject: RenderCustomPaint)
I/flutter ( 6559):         β””DefaultTextStyle(inherit: true; color: Color(0xd0ff0000); family: "monospace"; size: 48.0; weight: 900; decoration: double Color(0xffffff00) TextDecoration.underline)
I/flutter ( 6559):          β””MediaQuery(MediaQueryData(size: Size(411.4, 683.4), devicePixelRatio: 2.625, textScaleFactor: 1.0, padding: EdgeInsets(0.0, 24.0, 0.0, 0.0)))
I/flutter ( 6559):           β””LocaleQuery(null)
I/flutter ( 6559):            β””Title(color: Color(0xff2196f3))
I/flutter ( 6559):             β””Navigator([GlobalObjectKey<NavigatorState> _WidgetsAppState(552902158)]; state: NavigatorState(240327618; tracking 1 ticker))
I/flutter ( 6559):              β””Listener(listeners: down, up, cancel; behavior: defer-to-child; renderObject: RenderPointerListener)
I/flutter ( 6559):               β””AbsorbPointer(renderObject: RenderAbsorbPointer)
I/flutter ( 6559):                β””Focus([GlobalKey 489139594]; state: _FocusState(739584448))
I/flutter ( 6559):                 β””Semantics(container: true; renderObject: RenderSemanticsAnnotations)
I/flutter ( 6559):                  β””_FocusScope(this scope has focus; focused subscope: [GlobalObjectKey MaterialPageRoute<void>(875520219)])
I/flutter ( 6559):                   β””Overlay([GlobalKey 199833992]; state: OverlayState(619367313; entries: [OverlayEntry@248818791(opaque: false; maintainState: false), OverlayEntry@837336156(opaque: false; maintainState: true)]))
I/flutter ( 6559):                    β””_Theatre(renderObject: _RenderTheatre)
I/flutter ( 6559):                     β””Stack(renderObject: RenderStack)
I/flutter ( 6559):                      β”œ_OverlayEntry([GlobalKey 612888877]; state: _OverlayEntryState(739137453))
I/flutter ( 6559):                      β”‚β””IgnorePointer(ignoring: false; renderObject: RenderIgnorePointer)
I/flutter ( 6559):                      β”‚ β””ModalBarrier()
I/flutter ( 6559):                      β”‚  β””Semantics(container: true; renderObject: RenderSemanticsAnnotations)
I/flutter ( 6559):                      β”‚   β””GestureDetector()
I/flutter ( 6559):                      β”‚    β””RawGestureDetector(state: RawGestureDetectorState(39068508; gestures: tap; behavior: opaque))
I/flutter ( 6559):                      β”‚     β””_GestureSemantics(renderObject: RenderSemanticsGestureHandler)
I/flutter ( 6559):                      β”‚      β””Listener(listeners: down; behavior: opaque; renderObject: RenderPointerListener)
I/flutter ( 6559):                      β”‚       β””ConstrainedBox(BoxConstraints(biggest); renderObject: RenderConstrainedBox)
I/flutter ( 6559):                      β””_OverlayEntry([GlobalKey 727622716]; state: _OverlayEntryState(279971240))
I/flutter ( 6559):                       β””_ModalScope([GlobalKey 816151164]; state: _ModalScopeState(875510645))
I/flutter ( 6559):                        β””Focus([GlobalObjectKey MaterialPageRoute<void>(875520219)]; state: _FocusState(331487674))
I/flutter ( 6559):                         β””Semantics(container: true; renderObject: RenderSemanticsAnnotations)
I/flutter ( 6559):                          β””_FocusScope(this scope has focus)
I/flutter ( 6559):                           β””Offstage(offstage: false; renderObject: RenderOffstage)
I/flutter ( 6559):                            β””IgnorePointer(ignoring: false; renderObject: RenderIgnorePointer)
I/flutter ( 6559):                             β””_MountainViewPageTransition(animation: AnimationController(⏭ 1.000; paused; for MaterialPageRoute<void>(/))➩ProxyAnimation➩Cubic(0.40, 0.00, 0.20, 1.00)➩Tween<Offset>(Offset(0.0, 1.0) β†’ Offset(0.0, 0.0))➩Offset(0.0, 0.0); state: _AnimatedState(552160732))
I/flutter ( 6559):                              β””SlideTransition(animation: AnimationController(⏭ 1.000; paused; for MaterialPageRoute<void>(/))➩ProxyAnimation➩Cubic(0.40, 0.00, 0.20, 1.00)➩Tween<Offset>(Offset(0.0, 1.0) β†’ Offset(0.0, 0.0))➩Offset(0.0, 0.0); state: _AnimatedState(714726495))
I/flutter ( 6559):                               β””FractionalTranslation(renderObject: RenderFractionalTranslation)
I/flutter ( 6559):                                β””RepaintBoundary(renderObject: RenderRepaintBoundary)
I/flutter ( 6559):                                 β””PageStorage([GlobalKey 619728754])
I/flutter ( 6559):                                  β””_ModalScopeStatus(active)
I/flutter ( 6559):                                   β””AppHome()
I/flutter ( 6559):                                    β””Material(MaterialType.canvas; elevation: 0; state: _MaterialState(780114997))
I/flutter ( 6559):                                     β””AnimatedContainer(duration: 200ms; has background; state: _AnimatedContainerState(616063822; ticker inactive; has background))
I/flutter ( 6559):                                      β””Container(bg: BoxDecoration())
I/flutter ( 6559):                                       β””DecoratedBox(renderObject: RenderDecoratedBox)
I/flutter ( 6559):                                        β””Container(bg: BoxDecoration(backgroundColor: Color(0xfffafafa)))
I/flutter ( 6559):                                         β””DecoratedBox(renderObject: RenderDecoratedBox)
I/flutter ( 6559):                                          β””NotificationListener<LayoutChangedNotification>()
I/flutter ( 6559):                                           β””_InkFeature([GlobalKey ink renderer]; renderObject: _RenderInkFeatures)
I/flutter ( 6559):                                            β””AnimatedDefaultTextStyle(duration: 200ms; inherit: false; color: Color(0xdd000000); family: "Roboto"; size: 14.0; weight: 400; baseline: alphabetic; state: _AnimatedDefaultTextStyleState(427742350; ticker inactive))
I/flutter ( 6559):                                             β””DefaultTextStyle(inherit: false; color: Color(0xdd000000); family: "Roboto"; size: 14.0; weight: 400; baseline: alphabetic)
I/flutter ( 6559):                                              β””Center(alignment: Alignment.center; renderObject: RenderPositionedBox)
I/flutter ( 6559):                                               β””TextButton()
I/flutter ( 6559):                                                β””MaterialButton(state: _MaterialButtonState(398724090))
I/flutter ( 6559):                                                 β””ConstrainedBox(BoxConstraints(88.0<=w<=Infinity, h=36.0); renderObject: RenderConstrainedBox relayoutBoundary=up1)
I/flutter ( 6559):                                                  β””AnimatedDefaultTextStyle(duration: 200ms; inherit: false; color: Color(0xdd000000); family: "Roboto"; size: 14.0; weight: 500; baseline: alphabetic; state: _AnimatedDefaultTextStyleState(315134664; ticker inactive))
I/flutter ( 6559):                                                   β””DefaultTextStyle(inherit: false; color: Color(0xdd000000); family: "Roboto"; size: 14.0; weight: 500; baseline: alphabetic)
I/flutter ( 6559):                                                    β””IconTheme(color: Color(0xdd000000))
I/flutter ( 6559):                                                     β””InkWell(state: _InkResponseState<InkResponse>(369160267))
I/flutter ( 6559):                                                      β””GestureDetector()
I/flutter ( 6559):                                                       β””RawGestureDetector(state: RawGestureDetectorState(175370983; gestures: tap; behavior: opaque))
I/flutter ( 6559):                                                        β””_GestureSemantics(renderObject: RenderSemanticsGestureHandler relayoutBoundary=up2)
I/flutter ( 6559):                                                         β””Listener(listeners: down; behavior: opaque; renderObject: RenderPointerListener relayoutBoundary=up3)
I/flutter ( 6559):                                                          β””Container(padding: EdgeInsets(16.0, 0.0, 16.0, 0.0))
I/flutter ( 6559):                                                           β””Padding(renderObject: RenderPadding relayoutBoundary=up4)
I/flutter ( 6559):                                                            β””Center(alignment: Alignment.center; widthFactor: 1.0; renderObject: RenderPositionedBox relayoutBoundary=up5)
I/flutter ( 6559):                                                             β””Text("Dump App")
I/flutter ( 6559):                                                              β””RichText(renderObject: RenderParagraph relayoutBoundary=up6)

This is the β€œflattened” tree, showing all the widgets projected through their various build functions. (This is the tree you obtain if you call toStringDeep() on the root of the widget tree.) You’ll see a lot of widgets in there that don’t appear in your application’s source, because they are inserted by the framework’s widgets’ build functions. For example, InkFeature is an implementation detail of the Material widget.

Since the debugDumpApp() call is invoked when the button changes from being pressed to being released, it coincides with the TextButton object calling setState() and thus marking itself dirty. That is why, when you look at the dump you should see that specific object marked as β€œdirty”. You can also see what gesture listeners have been registered; in this case, a single GestureDetector is listed, and it is listening only to a β€œtap” gesture (β€œtap” is the output of a TapGestureDetector’s toStringShort function).

If you write your own widgets, you can add information by overriding debugFillProperties(). Add DiagnosticsProperty objects to the method’s argument, and call the superclass method. This function is what the toString method uses to fill in the widget’s description.

Render tree

If you are trying to debug a layout issue, then the Widgets layer’s tree might be insufficiently detailed. In that case, you can dump the rendering tree by calling debugDumpRenderTree(). As with debugDumpApp(), you can call this more or less any time except during a layout or paint phase. As a general rule, calling it from a frame callback or an event handler is the best solution.

To call debugDumpRenderTree(), you need to add import 'package:flutter/rendering.dart'; to your source file.

The output for the previous tiny example would look something like the following:

I/flutter ( 6559): RenderView
I/flutter ( 6559):  β”‚ debug mode enabled - android
I/flutter ( 6559):  β”‚ window size: Size(1080.0, 1794.0) (in physical pixels)
I/flutter ( 6559):  β”‚ device pixel ratio: 2.625 (physical pixels per logical pixel)
I/flutter ( 6559):  β”‚ configuration: Size(411.4, 683.4) at 2.625x (in logical pixels)
I/flutter ( 6559):  β”‚
I/flutter ( 6559):  └─child: RenderCustomPaint
I/flutter ( 6559):    β”‚ creator: CustomPaint ← Banner ← CheckedModeBanner ←
I/flutter ( 6559):    β”‚   WidgetsApp-[GlobalObjectKey _MaterialAppState(1009803148)] ←
I/flutter ( 6559):    β”‚   Theme ← AnimatedTheme ← ScrollConfiguration ← MaterialApp ←
I/flutter ( 6559):    β”‚   [root]
I/flutter ( 6559):    β”‚ parentData: <none>
I/flutter ( 6559):    β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):    β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):    β”‚
I/flutter ( 6559):    └─child: RenderPointerListener
I/flutter ( 6559):      β”‚ creator: Listener ← Navigator-[GlobalObjectKey<NavigatorState>
I/flutter ( 6559):      β”‚   _WidgetsAppState(552902158)] ← Title ← LocaleQuery ← MediaQuery
I/flutter ( 6559):      β”‚   ← DefaultTextStyle ← CustomPaint ← Banner ← CheckedModeBanner ←
I/flutter ( 6559):      β”‚   WidgetsApp-[GlobalObjectKey _MaterialAppState(1009803148)] ←
I/flutter ( 6559):      β”‚   Theme ← AnimatedTheme ← β‹―
I/flutter ( 6559):      β”‚ parentData: <none>
I/flutter ( 6559):      β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):      β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):      β”‚ behavior: defer-to-child
I/flutter ( 6559):      β”‚ listeners: down, up, cancel
I/flutter ( 6559):      β”‚
I/flutter ( 6559):      └─child: RenderAbsorbPointer
I/flutter ( 6559):        β”‚ creator: AbsorbPointer ← Listener ←
I/flutter ( 6559):        β”‚   Navigator-[GlobalObjectKey<NavigatorState>
I/flutter ( 6559):        β”‚   _WidgetsAppState(552902158)] ← Title ← LocaleQuery ← MediaQuery
I/flutter ( 6559):        β”‚   ← DefaultTextStyle ← CustomPaint ← Banner ← CheckedModeBanner ←
I/flutter ( 6559):        β”‚   WidgetsApp-[GlobalObjectKey _MaterialAppState(1009803148)] ←
I/flutter ( 6559):        β”‚   Theme ← β‹―
I/flutter ( 6559):        β”‚ parentData: <none>
I/flutter ( 6559):        β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):        β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):        β”‚ absorbing: false
I/flutter ( 6559):        β”‚
I/flutter ( 6559):        └─child: RenderSemanticsAnnotations
I/flutter ( 6559):          β”‚ creator: Semantics ← Focus-[GlobalKey 489139594] ← AbsorbPointer
I/flutter ( 6559):          β”‚   ← Listener ← Navigator-[GlobalObjectKey<NavigatorState>
I/flutter ( 6559):          β”‚   _WidgetsAppState(552902158)] ← Title ← LocaleQuery ← MediaQuery
I/flutter ( 6559):          β”‚   ← DefaultTextStyle ← CustomPaint ← Banner ← CheckedModeBanner ←
I/flutter ( 6559):          β”‚   β‹―
I/flutter ( 6559):          β”‚ parentData: <none>
I/flutter ( 6559):          β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):          β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):          β”‚
I/flutter ( 6559):          └─child: _RenderTheatre
I/flutter ( 6559):            β”‚ creator: _Theatre ← Overlay-[GlobalKey 199833992] ← _FocusScope ←
I/flutter ( 6559):            β”‚   Semantics ← Focus-[GlobalKey 489139594] ← AbsorbPointer ←
I/flutter ( 6559):            β”‚   Listener ← Navigator-[GlobalObjectKey<NavigatorState>
I/flutter ( 6559):            β”‚   _WidgetsAppState(552902158)] ← Title ← LocaleQuery ← MediaQuery
I/flutter ( 6559):            β”‚   ← DefaultTextStyle ← β‹―
I/flutter ( 6559):            β”‚ parentData: <none>
I/flutter ( 6559):            β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β”‚
I/flutter ( 6559):            β”œβ”€onstage: RenderStack
I/flutter ( 6559):            β•Ž β”‚ creator: Stack ← _Theatre ← Overlay-[GlobalKey 199833992] ←
I/flutter ( 6559):            β•Ž β”‚   _FocusScope ← Semantics ← Focus-[GlobalKey 489139594] ←
I/flutter ( 6559):            β•Ž β”‚   AbsorbPointer ← Listener ←
I/flutter ( 6559):            β•Ž β”‚   Navigator-[GlobalObjectKey<NavigatorState>
I/flutter ( 6559):            β•Ž β”‚   _WidgetsAppState(552902158)] ← Title ← LocaleQuery ← MediaQuery
I/flutter ( 6559):            β•Ž β”‚   ← β‹―
I/flutter ( 6559):            β•Ž β”‚ parentData: not positioned; offset=Offset(0.0, 0.0)
I/flutter ( 6559):            β•Ž β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž β”‚
I/flutter ( 6559):            β•Ž β”œβ”€child 1: RenderIgnorePointer
I/flutter ( 6559):            β•Ž β”‚ β”‚ creator: IgnorePointer ← _OverlayEntry-[GlobalKey 612888877] ←
I/flutter ( 6559):            β•Ž β”‚ β”‚   Stack ← _Theatre ← Overlay-[GlobalKey 199833992] ← _FocusScope
I/flutter ( 6559):            β•Ž β”‚ β”‚   ← Semantics ← Focus-[GlobalKey 489139594] ← AbsorbPointer ←
I/flutter ( 6559):            β•Ž β”‚ β”‚   Listener ← Navigator-[GlobalObjectKey<NavigatorState>
I/flutter ( 6559):            β•Ž β”‚ β”‚   _WidgetsAppState(552902158)] ← Title ← β‹―
I/flutter ( 6559):            β•Ž β”‚ β”‚ parentData: not positioned; offset=Offset(0.0, 0.0)
I/flutter ( 6559):            β•Ž β”‚ β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž β”‚ β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž β”‚ β”‚ ignoring: false
I/flutter ( 6559):            β•Ž β”‚ β”‚ ignoringSemantics: implicitly false
I/flutter ( 6559):            β•Ž β”‚ β”‚
I/flutter ( 6559):            β•Ž β”‚ └─child: RenderSemanticsAnnotations
I/flutter ( 6559):            β•Ž β”‚   β”‚ creator: Semantics ← ModalBarrier ← IgnorePointer ←
I/flutter ( 6559):            β•Ž β”‚   β”‚   _OverlayEntry-[GlobalKey 612888877] ← Stack ← _Theatre ←
I/flutter ( 6559):            β•Ž β”‚   β”‚   Overlay-[GlobalKey 199833992] ← _FocusScope ← Semantics ←
I/flutter ( 6559):            β•Ž β”‚   β”‚   Focus-[GlobalKey 489139594] ← AbsorbPointer ← Listener ← β‹―
I/flutter ( 6559):            β•Ž β”‚   β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž β”‚   β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž β”‚   β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž β”‚   β”‚
I/flutter ( 6559):            β•Ž β”‚   └─child: RenderSemanticsGestureHandler
I/flutter ( 6559):            β•Ž β”‚     β”‚ creator: _GestureSemantics ← RawGestureDetector ← GestureDetector
I/flutter ( 6559):            β•Ž β”‚     β”‚   ← Semantics ← ModalBarrier ← IgnorePointer ←
I/flutter ( 6559):            β•Ž β”‚     β”‚   _OverlayEntry-[GlobalKey 612888877] ← Stack ← _Theatre ←
I/flutter ( 6559):            β•Ž β”‚     β”‚   Overlay-[GlobalKey 199833992] ← _FocusScope ← Semantics ← β‹―
I/flutter ( 6559):            β•Ž β”‚     β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž β”‚     β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž β”‚     β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž β”‚     β”‚
I/flutter ( 6559):            β•Ž β”‚     └─child: RenderPointerListener
I/flutter ( 6559):            β•Ž β”‚       β”‚ creator: Listener ← _GestureSemantics ← RawGestureDetector ←
I/flutter ( 6559):            β•Ž β”‚       β”‚   GestureDetector ← Semantics ← ModalBarrier ← IgnorePointer ←
I/flutter ( 6559):            β•Ž β”‚       β”‚   _OverlayEntry-[GlobalKey 612888877] ← Stack ← _Theatre ←
I/flutter ( 6559):            β•Ž β”‚       β”‚   Overlay-[GlobalKey 199833992] ← _FocusScope ← β‹―
I/flutter ( 6559):            β•Ž β”‚       β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž β”‚       β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž β”‚       β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž β”‚       β”‚ behavior: opaque
I/flutter ( 6559):            β•Ž β”‚       β”‚ listeners: down
I/flutter ( 6559):            β•Ž β”‚       β”‚
I/flutter ( 6559):            β•Ž β”‚       └─child: RenderConstrainedBox
I/flutter ( 6559):            β•Ž β”‚           creator: ConstrainedBox ← Listener ← _GestureSemantics ←
I/flutter ( 6559):            β•Ž β”‚             RawGestureDetector ← GestureDetector ← Semantics ← ModalBarrier
I/flutter ( 6559):            β•Ž β”‚             ← IgnorePointer ← _OverlayEntry-[GlobalKey 612888877] ← Stack ←
I/flutter ( 6559):            β•Ž β”‚             _Theatre ← Overlay-[GlobalKey 199833992] ← β‹―
I/flutter ( 6559):            β•Ž β”‚           parentData: <none>
I/flutter ( 6559):            β•Ž β”‚           constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž β”‚           size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž β”‚           additionalConstraints: BoxConstraints(biggest)
I/flutter ( 6559):            β•Ž β”‚
I/flutter ( 6559):            β•Ž └─child 2: RenderSemanticsAnnotations
I/flutter ( 6559):            β•Ž   β”‚ creator: Semantics ← Focus-[GlobalObjectKey
I/flutter ( 6559):            β•Ž   β”‚   MaterialPageRoute<void>(875520219)] ← _ModalScope-[GlobalKey
I/flutter ( 6559):            β•Ž   β”‚   816151164] ← _OverlayEntry-[GlobalKey 727622716] ← Stack ←
I/flutter ( 6559):            β•Ž   β”‚   _Theatre ← Overlay-[GlobalKey 199833992] ← _FocusScope ←
I/flutter ( 6559):            β•Ž   β”‚   Semantics ← Focus-[GlobalKey 489139594] ← AbsorbPointer ←
I/flutter ( 6559):            β•Ž   β”‚   Listener ← β‹―
I/flutter ( 6559):            β•Ž   β”‚ parentData: not positioned; offset=Offset(0.0, 0.0)
I/flutter ( 6559):            β•Ž   β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž   β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž   β”‚
I/flutter ( 6559):            β•Ž   └─child: RenderOffstage
I/flutter ( 6559):            β•Ž     β”‚ creator: Offstage ← _FocusScope ← Semantics ←
I/flutter ( 6559):            β•Ž     β”‚   Focus-[GlobalObjectKey MaterialPageRoute<void>(875520219)] ←
I/flutter ( 6559):            β•Ž     β”‚   _ModalScope-[GlobalKey 816151164] ← _OverlayEntry-[GlobalKey
I/flutter ( 6559):            β•Ž     β”‚   727622716] ← Stack ← _Theatre ← Overlay-[GlobalKey 199833992] ←
I/flutter ( 6559):            β•Ž     β”‚   _FocusScope ← Semantics ← Focus-[GlobalKey 489139594] ← β‹―
I/flutter ( 6559):            β•Ž     β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž     β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž     β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž     β”‚ offstage: false
I/flutter ( 6559):            β•Ž     β”‚
I/flutter ( 6559):            β•Ž     └─child: RenderIgnorePointer
I/flutter ( 6559):            β•Ž       β”‚ creator: IgnorePointer ← Offstage ← _FocusScope ← Semantics ←
I/flutter ( 6559):            β•Ž       β”‚   Focus-[GlobalObjectKey MaterialPageRoute<void>(875520219)] ←
I/flutter ( 6559):            β•Ž       β”‚   _ModalScope-[GlobalKey 816151164] ← _OverlayEntry-[GlobalKey
I/flutter ( 6559):            β•Ž       β”‚   727622716] ← Stack ← _Theatre ← Overlay-[GlobalKey 199833992] ←
I/flutter ( 6559):            β•Ž       β”‚   _FocusScope ← Semantics ← β‹―
I/flutter ( 6559):            β•Ž       β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž       β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž       β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž       β”‚ ignoring: false
I/flutter ( 6559):            β•Ž       β”‚ ignoringSemantics: implicitly false
I/flutter ( 6559):            β•Ž       β”‚
I/flutter ( 6559):            β•Ž       └─child: RenderFractionalTranslation
I/flutter ( 6559):            β•Ž         β”‚ creator: FractionalTranslation ← SlideTransition ←
I/flutter ( 6559):            β•Ž         β”‚   _MountainViewPageTransition ← IgnorePointer ← Offstage ←
I/flutter ( 6559):            β•Ž         β”‚   _FocusScope ← Semantics ← Focus-[GlobalObjectKey
I/flutter ( 6559):            β•Ž         β”‚   MaterialPageRoute<void>(875520219)] ← _ModalScope-[GlobalKey
I/flutter ( 6559):            β•Ž         β”‚   816151164] ← _OverlayEntry-[GlobalKey 727622716] ← Stack ←
I/flutter ( 6559):            β•Ž         β”‚   _Theatre ← β‹―
I/flutter ( 6559):            β•Ž         β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž         β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž         β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž         β”‚ translation: Offset(0.0, 0.0)
I/flutter ( 6559):            β•Ž         β”‚ transformHitTests: true
I/flutter ( 6559):            β•Ž         β”‚
I/flutter ( 6559):            β•Ž         └─child: RenderRepaintBoundary
I/flutter ( 6559):            β•Ž           β”‚ creator: RepaintBoundary ← FractionalTranslation ←
I/flutter ( 6559):            β•Ž           β”‚   SlideTransition ← _MountainViewPageTransition ← IgnorePointer ←
I/flutter ( 6559):            β•Ž           β”‚   Offstage ← _FocusScope ← Semantics ← Focus-[GlobalObjectKey
I/flutter ( 6559):            β•Ž           β”‚   MaterialPageRoute<void>(875520219)] ← _ModalScope-[GlobalKey
I/flutter ( 6559):            β•Ž           β”‚   816151164] ← _OverlayEntry-[GlobalKey 727622716] ← Stack ← β‹―
I/flutter ( 6559):            β•Ž           β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž           β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž           β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž           β”‚ metrics: 83.3% useful (1 bad vs 5 good)
I/flutter ( 6559):            β•Ž           β”‚ diagnosis: this is a useful repaint boundary and should be kept
I/flutter ( 6559):            β•Ž           β”‚
I/flutter ( 6559):            β•Ž           └─child: RenderDecoratedBox
I/flutter ( 6559):            β•Ž             β”‚ creator: DecoratedBox ← Container ← AnimatedContainer ← Material
I/flutter ( 6559):            β•Ž             β”‚   ← AppHome ← _ModalScopeStatus ← PageStorage-[GlobalKey
I/flutter ( 6559):            β•Ž             β”‚   619728754] ← RepaintBoundary ← FractionalTranslation ←
I/flutter ( 6559):            β•Ž             β”‚   SlideTransition ← _MountainViewPageTransition ← IgnorePointer ←
I/flutter ( 6559):            β•Ž             β”‚   β‹―
I/flutter ( 6559):            β•Ž             β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž             β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž             β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž             β”‚ decoration:
I/flutter ( 6559):            β•Ž             β”‚   <no decorations specified>
I/flutter ( 6559):            β•Ž             β”‚ configuration: ImageConfiguration(bundle:
I/flutter ( 6559):            β•Ž             β”‚   PlatformAssetBundle@367106502(), devicePixelRatio: 2.625,
I/flutter ( 6559):            β•Ž             β”‚   platform: android)
I/flutter ( 6559):            β•Ž             β”‚
I/flutter ( 6559):            β•Ž             └─child: RenderDecoratedBox
I/flutter ( 6559):            β•Ž               β”‚ creator: DecoratedBox ← Container ← DecoratedBox ← Container ←
I/flutter ( 6559):            β•Ž               β”‚   AnimatedContainer ← Material ← AppHome ← _ModalScopeStatus ←
I/flutter ( 6559):            β•Ž               β”‚   PageStorage-[GlobalKey 619728754] ← RepaintBoundary ←
I/flutter ( 6559):            β•Ž               β”‚   FractionalTranslation ← SlideTransition ← β‹―
I/flutter ( 6559):            β•Ž               β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž               β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž               β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž               β”‚ decoration:
I/flutter ( 6559):            β•Ž               β”‚   backgroundColor: Color(0xfffafafa)
I/flutter ( 6559):            β•Ž               β”‚ configuration: ImageConfiguration(bundle:
I/flutter ( 6559):            β•Ž               β”‚   PlatformAssetBundle@367106502(), devicePixelRatio: 2.625,
I/flutter ( 6559):            β•Ž               β”‚   platform: android)
I/flutter ( 6559):            β•Ž               β”‚
I/flutter ( 6559):            β•Ž               └─child: _RenderInkFeatures
I/flutter ( 6559):            β•Ž                 β”‚ creator: _InkFeature-[GlobalKey ink renderer] ←
I/flutter ( 6559):            β•Ž                 β”‚   NotificationListener<LayoutChangedNotification> ← DecoratedBox
I/flutter ( 6559):            β•Ž                 β”‚   ← Container ← DecoratedBox ← Container ← AnimatedContainer ←
I/flutter ( 6559):            β•Ž                 β”‚   Material ← AppHome ← _ModalScopeStatus ← PageStorage-[GlobalKey
I/flutter ( 6559):            β•Ž                 β”‚   619728754] ← RepaintBoundary ← β‹―
I/flutter ( 6559):            β•Ž                 β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž                 β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž                 β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž                 β”‚
I/flutter ( 6559):            β•Ž                 └─child: RenderPositionedBox
I/flutter ( 6559):            β•Ž                   β”‚ creator: Center ← DefaultTextStyle ← AnimatedDefaultTextStyle ←
I/flutter ( 6559):            β•Ž                   β”‚   _InkFeature-[GlobalKey ink renderer] ←
I/flutter ( 6559):            β•Ž                   β”‚   NotificationListener<LayoutChangedNotification> ← DecoratedBox
I/flutter ( 6559):            β•Ž                   β”‚   ← Container ← DecoratedBox ← Container ← AnimatedContainer ←
I/flutter ( 6559):            β•Ž                   β”‚   Material ← AppHome ← β‹―
I/flutter ( 6559):            β•Ž                   β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž                   β”‚ constraints: BoxConstraints(w=411.4, h=683.4)
I/flutter ( 6559):            β•Ž                   β”‚ size: Size(411.4, 683.4)
I/flutter ( 6559):            β•Ž                   β”‚ alignment: Alignment.center
I/flutter ( 6559):            β•Ž                   β”‚ widthFactor: expand
I/flutter ( 6559):            β•Ž                   β”‚ heightFactor: expand
I/flutter ( 6559):            β•Ž                   β”‚
I/flutter ( 6559):            β•Ž                   └─child: RenderConstrainedBox relayoutBoundary=up1
I/flutter ( 6559):            β•Ž                     β”‚ creator: ConstrainedBox ← MaterialButton ← TextButton ← Center ←
I/flutter ( 6559):            β•Ž                     β”‚   DefaultTextStyle ← AnimatedDefaultTextStyle ←
I/flutter ( 6559):            β•Ž                     β”‚   _InkFeature-[GlobalKey ink renderer] ←
I/flutter ( 6559):            β•Ž                     β”‚   NotificationListener<LayoutChangedNotification> ← DecoratedBox
I/flutter ( 6559):            β•Ž                     β”‚   ← Container ← DecoratedBox ← Container ← β‹―
I/flutter ( 6559):            β•Ž                     β”‚ parentData: offset=Offset(156.7, 323.7)
I/flutter ( 6559):            β•Ž                     β”‚ constraints: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=683.4)
I/flutter ( 6559):            β•Ž                     β”‚ size: Size(98.0, 36.0)
I/flutter ( 6559):            β•Ž                     β”‚ additionalConstraints: BoxConstraints(88.0<=w<=Infinity, h=36.0)
I/flutter ( 6559):            β•Ž                     β”‚
I/flutter ( 6559):            β•Ž                     └─child: RenderSemanticsGestureHandler relayoutBoundary=up2
I/flutter ( 6559):            β•Ž                       β”‚ creator: _GestureSemantics ← RawGestureDetector ← GestureDetector
I/flutter ( 6559):            β•Ž                       β”‚   ← InkWell ← IconTheme ← DefaultTextStyle ←
I/flutter ( 6559):            β•Ž                       β”‚   AnimatedDefaultTextStyle ← ConstrainedBox ← MaterialButton ←
I/flutter ( 6559):            β•Ž                       β”‚   TextButton ← Center ← DefaultTextStyle ← β‹―
I/flutter ( 6559):            β•Ž                       β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž                       β”‚ constraints: BoxConstraints(88.0<=w<=411.4, h=36.0)
I/flutter ( 6559):            β•Ž                       β”‚ size: Size(98.0, 36.0)
I/flutter ( 6559):            β•Ž                       β”‚
I/flutter ( 6559):            β•Ž                       └─child: RenderPointerListener relayoutBoundary=up3
I/flutter ( 6559):            β•Ž                         β”‚ creator: Listener ← _GestureSemantics ← RawGestureDetector ←
I/flutter ( 6559):            β•Ž                         β”‚   GestureDetector ← InkWell ← IconTheme ← DefaultTextStyle ←
I/flutter ( 6559):            β•Ž                         β”‚   AnimatedDefaultTextStyle ← ConstrainedBox ← MaterialButton ←
I/flutter ( 6559):            β•Ž                         β”‚   TextButton ← Center ← β‹―
I/flutter ( 6559):            β•Ž                         β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž                         β”‚ constraints: BoxConstraints(88.0<=w<=411.4, h=36.0)
I/flutter ( 6559):            β•Ž                         β”‚ size: Size(98.0, 36.0)
I/flutter ( 6559):            β•Ž                         β”‚ behavior: opaque
I/flutter ( 6559):            β•Ž                         β”‚ listeners: down
I/flutter ( 6559):            β•Ž                         β”‚
I/flutter ( 6559):            β•Ž                         └─child: RenderPadding relayoutBoundary=up4
I/flutter ( 6559):            β•Ž                           β”‚ creator: Padding ← Container ← Listener ← _GestureSemantics ←
I/flutter ( 6559):            β•Ž                           β”‚   RawGestureDetector ← GestureDetector ← InkWell ← IconTheme ←
I/flutter ( 6559):            β•Ž                           β”‚   DefaultTextStyle ← AnimatedDefaultTextStyle ← ConstrainedBox ←
I/flutter ( 6559):            β•Ž                           β”‚   MaterialButton ← β‹―
I/flutter ( 6559):            β•Ž                           β”‚ parentData: <none>
I/flutter ( 6559):            β•Ž                           β”‚ constraints: BoxConstraints(88.0<=w<=411.4, h=36.0)
I/flutter ( 6559):            β•Ž                           β”‚ size: Size(98.0, 36.0)
I/flutter ( 6559):            β•Ž                           β”‚ padding: EdgeInsets(16.0, 0.0, 16.0, 0.0)
I/flutter ( 6559):            β•Ž                           β”‚
I/flutter ( 6559):            β•Ž                           └─child: RenderPositionedBox relayoutBoundary=up5
I/flutter ( 6559):            β•Ž                             β”‚ creator: Center ← Padding ← Container ← Listener ←
I/flutter ( 6559):            β•Ž                             β”‚   _GestureSemantics ← RawGestureDetector ← GestureDetector ←
I/flutter ( 6559):            β•Ž                             β”‚   InkWell ← IconTheme ← DefaultTextStyle ←
I/flutter ( 6559):            β•Ž                             β”‚   AnimatedDefaultTextStyle ← ConstrainedBox ← β‹―
I/flutter ( 6559):            β•Ž                             β”‚ parentData: offset=Offset(16.0, 0.0)
I/flutter ( 6559):            β•Ž                             β”‚ constraints: BoxConstraints(56.0<=w<=379.4, h=36.0)
I/flutter ( 6559):            β•Ž                             β”‚ size: Size(66.0, 36.0)
I/flutter ( 6559):            β•Ž                             β”‚ alignment: Alignment.center
I/flutter ( 6559):            β•Ž                             β”‚ widthFactor: 1.0
I/flutter ( 6559):            β•Ž                             β”‚ heightFactor: expand
I/flutter ( 6559):            β•Ž                             β”‚
I/flutter ( 6559):            β•Ž                             └─child: RenderParagraph relayoutBoundary=up6
I/flutter ( 6559):            β•Ž                               β”‚ creator: RichText ← Text ← Center ← Padding ← Container ←
I/flutter ( 6559):            β•Ž                               β”‚   Listener ← _GestureSemantics ← RawGestureDetector ←
I/flutter ( 6559):            β•Ž                               β”‚   GestureDetector ← InkWell ← IconTheme ← DefaultTextStyle ← β‹―
I/flutter ( 6559):            β•Ž                               β”‚ parentData: offset=Offset(0.0, 10.0)
I/flutter ( 6559):            β•Ž                               β”‚ constraints: BoxConstraints(0.0<=w<=379.4, 0.0<=h<=36.0)
I/flutter ( 6559):            β•Ž                               β”‚ size: Size(66.0, 16.0)
I/flutter ( 6559):            β•Ž                               β•˜β•β•¦β•β• text ═══
I/flutter ( 6559):            β•Ž                                 β•‘ TextSpan:
I/flutter ( 6559):            β•Ž                                 β•‘   inherit: false
I/flutter ( 6559):            β•Ž                                 β•‘   color: Color(0xdd000000)
I/flutter ( 6559):            β•Ž                                 β•‘   family: "Roboto"
I/flutter ( 6559):            β•Ž                                 β•‘   size: 14.0
I/flutter ( 6559):            β•Ž                                 β•‘   weight: 500
I/flutter ( 6559):            β•Ž                                 β•‘   baseline: alphabetic
I/flutter ( 6559):            β•Ž                                 β•‘   "Dump App"
I/flutter ( 6559):            β•Ž                                 β•šβ•β•β•β•β•β•β•β•β•β•β•
I/flutter ( 6559):            β•Ž
I/flutter ( 6559):            β””β•Œno offstage children

This is the output of the root RenderObject object’s toStringDeep() function.

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 example, in the previous dump you can see that the window size, Size(411.4, 683.4), is used to force all the boxes down to the RenderPositionedBox to be the size of the screen, with constraints of BoxConstraints(w=411.4, h=683.4). The RenderPositionedBox, which the dump says was created by a Center widget (as described by the creator field), sets its child’s constraints to a loose version of this: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=683.4). The child, a RenderPadding, further inserts these constraints to ensure there is room for the padding, and thus the RenderConstrainedBox has a loose constraint of BoxConstraints(0.0<=w<=395.4, 0.0<=h<=667.4). This object, which the creator field tells us is probably part of the TextButton’s definition, sets a minimum width of 88 pixels on its contents and a specific height of 36.0. (This is the TextButton class implementing the Material Design guidelines regarding button dimensions.)

The inner-most RenderPositionedBox loosens the constraints again, this time to center the text within the button. The RenderParagraph picks its size based on its contents. If you now follow the sizes back up the chain, you’ll see how the text’s size is what influences the width of all the boxes that form the button, as they all take their child’s dimensions to size themselves.

Another way to notice this is by looking at the β€œrelayoutSubtreeRoot” part of the descriptions of each box, which essentially tells you how many ancestors depend on this element’s size in some way. Thus the RenderParagraph has a relayoutSubtreeRoot=up8, meaning that when the RenderParagraph is dirtied, eight ancestors also have to be dirtied because they might be affected by the new dimensions.

If you write your own render objects, you can add information to the dump by overriding debugFillProperties(). Add DiagnosticsProperty objects to the method’s argument, and call the superclass method.

Layer tree

If you are trying to debug a compositing issue, you can use debugDumpLayerTree(). For the previous example, it would output:

I/flutter : TransformLayer
I/flutter :  β”‚ creator: [root]
I/flutter :  β”‚ offset: Offset(0.0, 0.0)
I/flutter :  β”‚ transform:
I/flutter :  β”‚   [0] 3.5,0.0,0.0,0.0
I/flutter :  β”‚   [1] 0.0,3.5,0.0,0.0
I/flutter :  β”‚   [2] 0.0,0.0,1.0,0.0
I/flutter :  β”‚   [3] 0.0,0.0,0.0,1.0
I/flutter :  β”‚
I/flutter :  β”œβ”€child 1: OffsetLayer
I/flutter :  β”‚ β”‚ creator: RepaintBoundary ← _FocusScope ← Semantics ← Focus-[GlobalObjectKey MaterialPageRoute(560156430)] ← _ModalScope-[GlobalKey 328026813] ← _OverlayEntry-[GlobalKey 388965355] ← Stack ← Overlay-[GlobalKey 625702218] ← Navigator-[GlobalObjectKey _MaterialAppState(859106034)] ← Title ← β‹―
I/flutter :  β”‚ β”‚ offset: Offset(0.0, 0.0)
I/flutter :  β”‚ β”‚
I/flutter :  β”‚ └─child 1: PictureLayer
I/flutter :  β”‚
I/flutter :  └─child 2: PictureLayer

This is the output of calling toStringDeep on the root Layer object.

The transform at the root is the transform that applies the device pixel ratio; in this case, a ratio of 3.5 device pixels for every logical pixel.

The RepaintBoundary widget, which creates a RenderRepaintBoundary in the render tree, creates a new layer in the layer tree. This is used to reduce how much needs to be repainted.

Semantics tree

You can also obtain a dump of the Semantics tree (the tree presented to the system accessibility APIs) using debugDumpSemanticsTree(). To use this, you have to have first enable accessibility, for example, by enabling a system accessibility tool or the SemanticsDebugger.

For the previous example, it would output the following:

I/flutter : SemanticsNode(0; Rect.fromLTRB(0.0, 0.0, 411.4, 683.4))
I/flutter :  β”œSemanticsNode(1; Rect.fromLTRB(0.0, 0.0, 411.4, 683.4))
I/flutter :  β”‚ β””SemanticsNode(2; Rect.fromLTRB(0.0, 0.0, 411.4, 683.4); canBeTapped)
I/flutter :  β””SemanticsNode(3; Rect.fromLTRB(0.0, 0.0, 411.4, 683.4))
I/flutter :    β””SemanticsNode(4; Rect.fromLTRB(0.0, 0.0, 82.0, 36.0); canBeTapped; "Dump App")

Scheduling

To find out where your events happen relative to the frame’s begin/end, you can toggle the debugPrintBeginFrameBanner and the debugPrintEndFrameBanner booleans to print the beginning and end of the frames to the console.

For example:

I/flutter : β–„β–„β–„β–„β–„β–„β–„β–„ Frame 12         30s 437.086ms β–„β–„β–„β–„β–„β–„β–„β–„
I/flutter : Debug print: Am I performing this work more than once per frame?
I/flutter : Debug print: Am I performing this work more than once per frame?
I/flutter : β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€

The debugPrintScheduleFrameStacks flag can also be used to print the call stack causing the current frame to be scheduled.

Debug flags: layout

You can also debug a layout problem visually, by setting debugPaintSizeEnabled to true. This is a boolean from the rendering library. It can be enabled at any time and affects all painting while it is true. The easiest way to set it is at the top of your void main() entry point. See an example in the following code:

//add import to rendering library
import 'package:flutter/rendering.dart';

void main() {
  debugPaintSizeEnabled=true;
  runApp(MyApp());
}

When it is enabled, all boxes get a bright teal border, padding (from widgets like Padding) is shown in faded blue with a darker blue box around the child, alignment (from widgets like Center and Align) is shown with yellow arrows, and spacers (from widgets like Container when they have no child) are shown in gray.

The debugPaintBaselinesEnabled flag does something similar but for objects with baselines. The alphabetic baseline is shown in bright green and the ideographic baseline in orange.

The debugPaintPointersEnabled flag turns on a special mode whereby any objects that are being tapped get highlighted in teal. This can help you determine whether an object is somehow failing to correctly hit test (which might happen if, for instance, it is actually outside the bounds of its parent and thus not being considered for hit testing in the first place).

If you’re trying to debug compositor layers, for example to determine whether and where to add RepaintBoundary widgets, you can use the debugPaintLayerBordersEnabled flag, which outlines each layer’s bounds in orange, or the debugRepaintRainbowEnabled flag, which causes layers to be overlayed with a rotating set of colors whenever they are repainted.

All of these flags only work in debug mode. In general, anything in the Flutter framework that starts with β€œdebug...” only works in debug mode.

Debugging animations

Set the timeDilation variable (from the scheduler library) to a number greater than 1.0, for instance, 50.0. It’s best to only set this once on app startup. If you change it on the fly, especially if you reduce it while animations are running, it’s possible that the framework will observe time going backwards, which will probably result in asserts and generally interfere with your efforts.

Debug flags: performance

Flutter provides a wide variety of debug flags and functions to help you debug your app at various points along the development cycle. To use these features, you must compile in debug mode. The following list, while not complete, highlights some of flags (and one function) from the rendering library for debugging performance issues.

You can set these flags either by editing the framework code, or by importing the module and setting the value in your main() method, following by a hot restart.

debugDumpRenderTree()

Call this function when not in a layout or repaint phase to dump the rendering tree to the console. (Pressing t from flutter run calls this command.) Search for β€œRepaintBoundary” to see diagnostics on how useful a boundary is.

debugPaintLayerBordersEnabled

PENDING

debugRepaintRainbowEnabled

You can enable this flag in the Flutter inspector by selecting the Highlight Repaints button. If any static widgets are rotating through the colors of the rainbow (for example, a static header), those areas are candidates for adding repaint boundaries.

debugPrintMarkNeedsLayoutStacks

Enable this flag if you’re seeing more layouts than you expect (for example, on the timeline, on a profile, or from a print statement inside a layout method). Once enabled, the console is flooded with stack traces showing why each render object is being marked dirty for layout. You can use the debugPrintStack() method from the services library to print your own stack traces on demand, if this kind of approach is useful to you.

debugPrintMarkNeedsPaintStacks

Similar to debugPrintMarkNeedsLayoutStacks, but for excess painting. You can use the debugPrintStack() method from the services library to print your own stack traces on demand, if this kind of approach is useful to you.

Tracing Dart code performance

To perform custom performance traces programmatically and measure wall/CPU time of arbitrary segments of Dart code similar to what would be done on Android with systrace, use dart:developer Timeline utilities to wrap the code you want to measure such as:

import 'dart:developer';

Timeline.startSync('interesting function');
// iWonderHowLongThisTakes();
Timeline.finishSync();

Then open your app’s Observatory’s timeline page, check the β€˜Dart’ recording option and perform the function you want to measure.

Refreshing the page displays the chronological timeline records of your app in Chrome’s tracing tool.

Be sure to run your app in profile mode to ensure that the runtime performance characteristics closely match that of your final product.

Performance overlay

You can programmatically enable the PerformanceOverlay widget by setting the showPerformanceOverlay property to true on the MaterialApp, CupertinoApp, or WidgetsApp constructor:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      showPerformanceOverlay: true,
      title: 'My Awesome App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'My Awesome App'),
    );
  }
}

(If you’re not using MaterialApp, CupertinoApp, or WidgetsApp, you can get the same effect by wrapping your application in a stack and putting a widget on your stack that was created by calling PerformanceOverlay.allEnabled().)

For information on how to interpret the graphs in the overlay, see The performance overlay in Profiling Flutter performance.

Widget alignment grid

You can programmatically overlay a Material Design baseline grid on top of your app to help verify alignments by using the debugShowMaterialGrid argument in the MaterialApp constructor.

In non-Material applications, you can achieve a similar effect by using a GridPaper widget directly.