Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I override debugFillProperties in Flutter?

Tags:

flutter

dart

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"));
  }
like image 504
nikhil Avatar asked Oct 15 '22 20:10

nikhil


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

like image 160
Reza Esfandiari Avatar answered Oct 24 '22 01:10

Reza Esfandiari


Also, the information from debugFillProperties will be shown in the output from a debugDumpApp call.

See Debugging App Programmatically -> Widget Tree section for more details.

like image 1
pasul Avatar answered Oct 24 '22 01:10

pasul