Skip to content

Instantly share code, notes, and snippets.

@abhaysood
Last active May 28, 2021 12:53
Show Gist options
  • Save abhaysood/e5808b221c3ece51408b60f39ef5b4b8 to your computer and use it in GitHub Desktop.
Save abhaysood/e5808b221c3ece51408b60f39ef5b4b8 to your computer and use it in GitHub Desktop.
Blog: Enrich the Flutter Inspector with Diagnosticable properties
class MyColorScheme with Diagnosticable {
final Color textColor;
final Color backgroundColor;
MyColorScheme(this.textColor, this.backgroundColor);
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(ColorProperty('textColor', textColor));
properties.add(ColorProperty('backgroundColor', backgroundColor));
}
}
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));
}
// Code omitted for brevity.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment