matchingTarget属性
指向触发事件的CSS选择器匹配的元素的指针。如果此事件未与任何事件委托关联,访问此值将抛出UnsupportedError。
实现
Element get matchingTarget {
if (_selector == null) {
throw new UnsupportedError('Cannot call matchingTarget if this Event did'
' not arise as a result of event delegation.');
}
Element? currentTarget = this.currentTarget as Element?;
Element? target = this.target as Element?;
var matchedTarget;
do {
if (target!.matches(_selector!)) return target;
target = target.parent;
} while (target != null && target != currentTarget!.parent);
throw new StateError('No selector matched for populating matchedTarget.');
}