GestureRecognizer cleanup
Summary
#OneSequenceGestureRecognizer.addAllowedPointer()
was changed to take a
PointerDownEvent
, like its superclass. Previously, it accepted the more
general PointerEvent
type, which was incorrect.
Context
#The framework only ever passes PointerDownEvent
objects to
addAllowedPointer()
. Declaring
OneSequenceGestureRecognizer.addAllowedPointer()
to take the more general
type was confusing, and caused OneSequenceGestureRecognizer
subclasses to
have to cast their argument to the right class.
Description of change
#The previous declaration forced OneSequenceGestureRecognizer
descendants to
override addAllowedPointer()
like so:
class CustomGestureRecognizer extends ScaleGestureRecognizer {
@override
void addAllowedPointer(PointerEvent event) {
// insert custom handling of event here...
super.addAllowedPointer(event);
}
}
The new method declaration will cause this code to fail with the following error message:
super.addAllowedPointer(event); The argument type 'PointerEvent' can't be assigned to the parameter type 'PointerDownEvent'.
#argument_type_not_assignable
Migration guide
#Code before migration:
class CustomGestureRecognizer extends ScaleGestureRecognizer {
@override
void addAllowedPointer(PointerEvent event) {
// insert custom handling of event here...
super.addAllowedPointer(event);
}
}
Code after migration:
class CustomGestureRecognizer extends ScaleGestureRecognizer {
@override
void addAllowedPointer(PointerDownEvent event) {
// insert custom handling of event here...
super.addAllowedPointer(event);
}
}
Timeline
#Landed in version: 2.3.0-13.0.pre
In stable release: 2.5
References
#API documentation:
Relevant PR:
除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2024-10-09。 查看文档源码 或者 为本页面内容提出建议。