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 {
/// Creates a widget that visualizes the semantics for the child.
///
/// 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.
///
/// {@macro flutter.widgets.child}
final Widget child;
/// The [TextStyle] to use when rendering semantics labels.
final TextStyle labelStyle;
@override
_SemanticsDebuggerState createState() => _SemanticsDebuggerState();
}
......@@ -150,6 +165,7 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindi
_client.generation,
_lastPointerDownLocation, // in physical pixels
WidgetsBinding.instance.window.devicePixelRatio,
widget.labelStyle,
),
child: GestureDetector(
behavior: HitTestBehavior.opaque,
......@@ -195,12 +211,13 @@ class _SemanticsClient extends ChangeNotifier {
}
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 int generation;
final Offset pointerPosition; // in physical pixels
final double devicePixelRatio;
final TextStyle labelStyle;
SemanticsNode get _rootSemanticsNode {
return owner.semanticsOwner?.rootSemanticsNode;
......@@ -306,11 +323,7 @@ class _SemanticsDebuggerPainter extends CustomPainter {
canvas.clipRect(rect);
final TextPainter textPainter = TextPainter()
..text = TextSpan(
style: const TextStyle(
color: Color(0xFF000000),
fontSize: 10.0,
height: 0.8,
),
style: labelStyle,
text: message,
)
..textDirection = TextDirection.ltr // _getMessage always returns LTR text, even if node.label is RTL
......
......@@ -460,6 +460,26 @@ void main() {
'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({
......
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