In Flutter, how can I print out the current widget tree in a widget unit test, in order to understand the current state of the UI for debugging?
(For example, in React/Ensyme, I could use debug(). Is there something comparable in Flutter?)
Inspecting a widget To locate individual UI elements in the widget tree, click the Select Widget Mode button in the toolbar. This puts the app on the device into a “widget select” mode. Click any widget in the app's UI; this selects the widget on the app's screen, and scrolls the widget tree to the corresponding node.
findsOneWidget top-level constant Null safety Matcher const findsOneWidget. Asserts that the Finder locates at exactly one widget in the widget tree.
The widget tree is how you create your UI; you position widgets within each other to build simple and complex layouts. Since just about everything in the Flutter framework is a widget, and as you start nesting them, the code can become harder to follow.
You can use debugDumpApp
This will print the widget tree based on the Diagnosticable interface, which both Widget, RenderObject and Element implements.
Note that for custom made widgets, you'll have to implement a method for their content to display in that tree: debugFillProperties
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With