When dispatching a semantic event, check if the node has been merged with parent (#20020)
This commit is contained in:
parent
63098f2bc8
commit
e9c8e36bde
@ -2206,7 +2206,7 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
|
||||
void sendSemanticsEvent(SemanticsEvent semanticsEvent) {
|
||||
if (owner.semanticsOwner == null)
|
||||
return;
|
||||
if (_semantics != null) {
|
||||
if (_semantics != null && !_semantics.isMergedIntoParent) {
|
||||
_semantics.sendEvent(semanticsEvent);
|
||||
} else if (parent != null) {
|
||||
final RenderObject renderParent = parent;
|
||||
|
@ -314,4 +314,54 @@ void main() {
|
||||
semanticsTester.dispose();
|
||||
SystemChannels.accessibility.setMockMessageHandler(null);
|
||||
});
|
||||
|
||||
testWidgets('switch sends semantic events from parent if fully merged', (WidgetTester tester) async {
|
||||
dynamic semanticEvent;
|
||||
bool value = false;
|
||||
SystemChannels.accessibility.setMockMessageHandler((dynamic message) {
|
||||
semanticEvent = message;
|
||||
});
|
||||
final SemanticsTester semanticsTester = new SemanticsTester(tester);
|
||||
|
||||
await tester.pumpWidget(
|
||||
new MaterialApp(
|
||||
home: new StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
void onChanged(bool newValue) {
|
||||
setState(() {
|
||||
value = newValue;
|
||||
});
|
||||
}
|
||||
return new Material(
|
||||
child: new MergeSemantics(
|
||||
child: new ListTile(
|
||||
leading: const Text('test'),
|
||||
onTap: () {
|
||||
onChanged(!value);
|
||||
},
|
||||
trailing: new Switch(
|
||||
value: value,
|
||||
onChanged: onChanged,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byType(MergeSemantics));
|
||||
final RenderObject object = tester.firstRenderObject(find.byType(MergeSemantics));
|
||||
|
||||
expect(value, true);
|
||||
expect(semanticEvent, <String, dynamic>{
|
||||
'type': 'tap',
|
||||
'nodeId': object.debugSemantics.id,
|
||||
'data': <String, dynamic>{},
|
||||
});
|
||||
expect(object.debugSemantics.getSemanticsData().hasAction(SemanticsAction.tap), true);
|
||||
|
||||
semanticsTester.dispose();
|
||||
SystemChannels.accessibility.setMockMessageHandler(null);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user