13

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?)

Matt R
  • 9,892
  • 10
  • 50
  • 83

1 Answers1

19

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

Rémi Rousselet
  • 256,336
  • 79
  • 519
  • 432
  • Looks promising, unfortunately it just throws an exception when I call it: https://gist.github.com/mdr/915a269a6a314d49f90041736480c5a4 – Matt R Oct 28 '19 at 07:59
  • 2
    Consider making an issue. That assert is very unclear. – Rémi Rousselet Oct 28 '19 at 08:41
  • By elimination, looks to be a problem in some of the theme customisation I was using. I will try and make a minimum reproducible test case and submit it as a bug. But otherwise, that works a treat, thanks! – Matt R Nov 05 '19 at 18:25