When should I override debugFillProperties in Flutter?

Viewed 782

Why should I use debugFillProperties in the stateful widget in Flutter? I have seen Some flutter Built-in stateful widgets Like Slider using this method.

I went through Flutter Docs given here. I'm still not able to understand the practical usage of debugFillProperties. When or why use it?

I tried It in My example code, Still Not able to understand. I did not find any docs or relevant information was found about this method in Flutter.

  double? min;
  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    print("--------------Debug-------------");
    properties.add(IntProperty('min', min, defaultValue: 5, ifNull: "nulll"));
  }
2 Answers

By overriding the debugFillProperties function, we can show the current value of a variable (state) in the Details Tree

example: without overriding this method:

class _MyHomePageState extends State<MyHomePage> {
  late MyColorScheme _myColorScheme;
  int _counter = 0;

  @override
  void initState() {
    _myColorScheme = MyColorScheme(Colors.black, Colors.white);
    super.initState();
  }
}

enter image description here

with overriding this method:

class _MyHomePageState extends State<MyHomePage> {
  late MyColorScheme _myColorScheme;
  int _counter = 0;

  @override
  void initState() {
    _myColorScheme = MyColorScheme(Colors.black, Colors.white);
    super.initState();
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(IntProperty('_counter', _counter));
    properties.add(
        DiagnosticsProperty<MyColorScheme>('myColorScheme', _myColorScheme));
  }

}

enter image description here

Related