Created
May 26, 2021 08:25
-
-
Save abhaysood/a082c16905ca93b672b0120d2b041331 to your computer and use it in GitHub Desktop.
Flutter Diagnosticable demonstration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/foundation.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark(), | |
home: Scaffold( | |
body: Center( | |
child: MyWidget( | |
diagnosticable: WithDiagnosticable( | |
string: "string", | |
integer: 1, | |
color: Colors.red, | |
), | |
notDiagnosticable: NotDiagnosticable( | |
string: "string", | |
integer: 1, | |
color: Colors.red, | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
final WithDiagnosticable diagnosticable; | |
final NotDiagnosticable notDiagnosticable; | |
const MyWidget({ | |
Key? key, | |
required this.diagnosticable, | |
required this.notDiagnosticable, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Text('Hello, World!', style: Theme.of(context).textTheme.headline4); | |
} | |
@override | |
void debugFillProperties(DiagnosticPropertiesBuilder properties) { | |
super.debugFillProperties(properties); | |
properties.add(DiagnosticsProperty<WithDiagnosticable>( | |
'diagnosticable', diagnosticable)); | |
DiagnosticsProperty<NotDiagnosticable>( | |
'notDiagnosticable', notDiagnosticable); | |
} | |
} | |
class WithDiagnosticable with Diagnosticable { | |
final String string; | |
final int integer; | |
final Color color; | |
WithDiagnosticable({ | |
required this.string, | |
required this.integer, | |
required this.color, | |
}); | |
@override | |
void debugFillProperties(DiagnosticPropertiesBuilder properties) { | |
super.debugFillProperties(properties); | |
properties.add(StringProperty('string', string)); | |
properties.add(IntProperty('int', integer)); | |
properties.add(ColorProperty('color', color)); | |
} | |
} | |
class NotDiagnosticable { | |
final String string; | |
final int integer; | |
final Color color; | |
NotDiagnosticable({ | |
required this.string, | |
required this.integer, | |
required this.color, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment