text
stringlengths 1
372
|
|---|
<topic_end>
|
<topic_start>
|
print the widget tree
|
to dump the state of the widgets library,
|
call the debugDumpApp() function.
|
<topic_end>
|
<topic_start>
|
example 4: call debugDumpApp()
|
<code_start>
|
import 'package:flutter/material.dart';
|
void main() {
|
runApp(
|
const MaterialApp(
|
home: AppHome(),
|
),
|
);
|
}
|
class AppHome extends StatelessWidget {
|
const AppHome({super.key});
|
@override
|
widget build(BuildContext context) {
|
return material(
|
child: center(
|
child: TextButton(
|
onPressed: () {
|
debugDumpApp();
|
},
|
child: const Text('Dump widget tree'),
|
),
|
),
|
);
|
}
|
}
|
<code_end>
|
this function recursively calls the toStringDeep() method starting with
|
the root of the widget tree. it returns a “flattened” tree.
|
example 4 produces the following widget tree. it includes:
|
many widgets that don’t appear in your app’s source.
|
the framework’s widgets’ build functions insert them during the build.
|
the following tree, for example, shows _InkFeatures.
|
that class implements part of the material widget.
|
it doesn’t appear anywhere in the code in example 4.
|
when the button changes from being pressed to being released,
|
this invokes the debugDumpApp() function.
|
it also coincides with the TextButton object calling setState()
|
and thus marking itself dirty.
|
this explains why a flutter marks a specific object as “dirty”.
|
when you review the widget tree, look for a line that resembles the following:
|
if you write your own widgets, override the
|
debugFillProperties() method to add information.
|
add DiagnosticsProperty objects to the method’s argument
|
and call the superclass method.
|
the toString method uses this function to fill in the widget’s description.
|
<topic_end>
|
<topic_start>
|
print the render tree
|
when debugging a layout issue, the widgets layer’s tree might lack detail.
|
the next level of debugging might require a render tree.
|
to dump the render tree:
|
<topic_end>
|
<topic_start>
|
example 5: call debugDumpRenderTree()
|
<code_start>
|
import 'package:flutter/material.dart';
|
void main() {
|
runApp(
|
const MaterialApp(
|
home: AppHome(),
|
),
|
);
|
}
|
class AppHome extends StatelessWidget {
|
const AppHome({super.key});
|
@override
|
widget build(BuildContext context) {
|
return material(
|
child: center(
|
child: TextButton(
|
onPressed: () {
|
debugDumpRenderTree();
|
},
|
child: const Text('Dump render tree'),
|
),
|
),
|
);
|
}
|
}
|
<code_end>
|
when debugging layout issues, look at the size and constraints fields.
|
the constraints flow down the tree and the sizes flow back up.
|
in the render tree for example 5:
|
the RenderView, or window size, limits all render objects up to and
|
including RenderPositionedBox#dc1df render object
|
to the size of the screen.
|
this example sets the size to size(800.0, 600.0)
|
the constraints property of each render object limits the size
|
of each child. this property takes the BoxConstraints render object as a value.
|
starting with the RenderSemanticsAnnotations#fe6b5, the constraint equals
|
BoxConstraints(w=800.0, h=600.0).
|
the center widget created the RenderPositionedBox#dc1df render object
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.