enableElementTargeting function
Enables element targeting by listening for semantics tree updates.
On every update the tree is walked, positions are computed in logical
pixels, and the resulting list is sent to native via methodChannel.
Implementation
void enableElementTargeting(MethodChannel methodChannel) {
_semanticsHandle = SemanticsBinding.instance.ensureSemantics();
_semanticsListener = () => _semanticsChanged(methodChannel);
// Defer listener setup to after the current frame so that
// ensureSemantics() has propagated and the view's SemanticsOwner exists.
SchedulerBinding.instance.addPostFrameCallback((_) {
_viewPipelineOwner = _getViewPipelineOwner();
_viewPipelineOwner?.semanticsOwner?.addListener(_semanticsListener!);
_semanticsChanged(methodChannel);
});
}