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:
Unless stated otherwise, the documentation on this site reflects the latest stable version of Flutter. Page last updated on 2024-04-04. View source or report an issue.