Commit 6b09543e authored by Mehmet Fidanboylu's avatar Mehmet Fidanboylu Committed by Michael Goderbauer

Allow customization of label styles for semantics debugger (#41730)

parent c7c8a6c4
...@@ -22,13 +22,28 @@ class SemanticsDebugger extends StatefulWidget { ...@@ -22,13 +22,28 @@ class SemanticsDebugger extends StatefulWidget {
/// Creates a widget that visualizes the semantics for the child. /// Creates a widget that visualizes the semantics for the child.
/// ///
/// The [child] argument must not be null. /// The [child] argument must not be null.
const SemanticsDebugger({ Key key, this.child }) : super(key: key); ///
/// [labelStyle] dictates the [TextStyle] used for the semantics labels.
const SemanticsDebugger({
Key key,
@required this.child,
this.labelStyle = const TextStyle(
color: Color(0xFF000000),
fontSize: 10.0,
height: 0.8,
),
}) : assert(child != null),
assert(labelStyle != null),
super(key: key);
/// The widget below this widget in the tree. /// The widget below this widget in the tree.
/// ///
/// {@macro flutter.widgets.child} /// {@macro flutter.widgets.child}
final Widget child; final Widget child;
/// The [TextStyle] to use when rendering semantics labels.
final TextStyle labelStyle;
@override @override
_SemanticsDebuggerState createState() => _SemanticsDebuggerState(); _SemanticsDebuggerState createState() => _SemanticsDebuggerState();
} }
...@@ -150,6 +165,7 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindi ...@@ -150,6 +165,7 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindi
_client.generation, _client.generation,
_lastPointerDownLocation, // in physical pixels _lastPointerDownLocation, // in physical pixels
WidgetsBinding.instance.window.devicePixelRatio, WidgetsBinding.instance.window.devicePixelRatio,
widget.labelStyle,
), ),
child: GestureDetector( child: GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
...@@ -195,12 +211,13 @@ class _SemanticsClient extends ChangeNotifier { ...@@ -195,12 +211,13 @@ class _SemanticsClient extends ChangeNotifier {
} }
class _SemanticsDebuggerPainter extends CustomPainter { class _SemanticsDebuggerPainter extends CustomPainter {
const _SemanticsDebuggerPainter(this.owner, this.generation, this.pointerPosition, this.devicePixelRatio); const _SemanticsDebuggerPainter(this.owner, this.generation, this.pointerPosition, this.devicePixelRatio, this.labelStyle);
final PipelineOwner owner; final PipelineOwner owner;
final int generation; final int generation;
final Offset pointerPosition; // in physical pixels final Offset pointerPosition; // in physical pixels
final double devicePixelRatio; final double devicePixelRatio;
final TextStyle labelStyle;
SemanticsNode get _rootSemanticsNode { SemanticsNode get _rootSemanticsNode {
return owner.semanticsOwner?.rootSemanticsNode; return owner.semanticsOwner?.rootSemanticsNode;
...@@ -306,11 +323,7 @@ class _SemanticsDebuggerPainter extends CustomPainter { ...@@ -306,11 +323,7 @@ class _SemanticsDebuggerPainter extends CustomPainter {
canvas.clipRect(rect); canvas.clipRect(rect);
final TextPainter textPainter = TextPainter() final TextPainter textPainter = TextPainter()
..text = TextSpan( ..text = TextSpan(
style: const TextStyle( style: labelStyle,
color: Color(0xFF000000),
fontSize: 10.0,
height: 0.8,
),
text: message, text: message,
) )
..textDirection = TextDirection.ltr // _getMessage always returns LTR text, even if node.label is RTL ..textDirection = TextDirection.ltr // _getMessage always returns LTR text, even if node.label is RTL
......
...@@ -460,6 +460,26 @@ void main() { ...@@ -460,6 +460,26 @@ void main() {
'textfield', 'textfield',
); );
}); });
testWidgets('SemanticsDebugger label style is used in the painter.', (WidgetTester tester) async {
final UniqueKey debugger = UniqueKey();
const TextStyle labelStyle = TextStyle(color: Colors.amber);
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: SemanticsDebugger(
key: debugger,
labelStyle: labelStyle,
child: Semantics(
label: 'label',
textDirection: TextDirection.ltr,
),
),
),
);
expect(_getSemanticsDebuggerPainter(debuggerKey: debugger, tester: tester).labelStyle, labelStyle);
});
} }
String _getMessageShownInSemanticsDebugger({ String _getMessageShownInSemanticsDebugger({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment