Skip to content

Instantly share code, notes, and snippets.

@mdebbar
Created February 20, 2020 23:54
Show Gist options
  • Save mdebbar/94759c080dc93c9bcf1d52c170533e8e to your computer and use it in GitHub Desktop.
Save mdebbar/94759c080dc93c9bcf1d52c170533e8e to your computer and use it in GitHub Desktop.
List<PointerEvent> is a List<dynamic>
import 'dart:html';
void main() {
window.addEventListener('pointermove', handlePointerMove);
}
void handlePointerMove(Event event) {
final PointerEvent pointerEvent = event;
final Iterable<Foo> fooList = expandEvent(pointerEvent).expand(
(PointerEvent e) => getFooListForEvent(e),
);
printIterable(fooList);
}
List<PointerEvent> expandEvent(PointerEvent event) {
final List<PointerEvent> coalescedEvents = event.getCoalescedEvents();
// Calling `.cast<PointerEvent>()` fixes the issue.
return coalescedEvents/* .cast<PointerEvent>() */;
}
List<Foo> getFooListForEvent(PointerEvent event) {
return <Foo>[Foo(event.client.x), Foo(event.client.y)];
}
void printIterable(Iterable<Foo> foos) {
for (Foo foo in foos) {
print(foo);
}
}
class Foo {
double _value;
Foo(this._value);
String toString() => _value.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment