setCanDrag method
Whether the user can drag the widget, for example to initiate a scroll.
Implementation
@override
void setCanDrag(bool canDrag) {
if (canDrag == _lastCanDrag && (!canDrag || axis == _lastAxisDirection)) return;
if (!canDrag) {
_gestureRecognizers = const <Type, GestureRecognizerFactory>{};
} else {
switch (axis) {
case Axis.vertical:
// Vertical drag gesture recognizer to trigger vertical scroll.
_gestureRecognizers = <Type, GestureRecognizerFactory>{
ScrollVerticalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<ScrollVerticalDragGestureRecognizer>(
() => ScrollVerticalDragGestureRecognizer(),
(ScrollVerticalDragGestureRecognizer instance) {
instance
..isAcceptedDrag = _isAcceptedVerticalDrag
..onDown = _handleDragDown
..onStart = _handleDragStart
..onUpdate = _handleDragUpdate
..onEnd = _handleDragEnd
..onCancel = _handleDragCancel
..minFlingDistance = _physics.minFlingDistance
..minFlingVelocity = _physics.minFlingVelocity
..maxFlingVelocity = _physics.maxFlingVelocity
..dragStartBehavior = dragStartBehavior;
},
),
};
break;
case Axis.horizontal:
// Horizontal drag gesture recognizer to horizontal vertical scroll.
_gestureRecognizers = <Type, GestureRecognizerFactory>{
ScrollHorizontalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<ScrollHorizontalDragGestureRecognizer>(
() => ScrollHorizontalDragGestureRecognizer(),
(ScrollHorizontalDragGestureRecognizer instance) {
instance
..isAcceptedDrag = _isAcceptedHorizontalDrag
..onDown = _handleDragDown
..onStart = _handleDragStart
..onUpdate = _handleDragUpdate
..onEnd = _handleDragEnd
..onCancel = _handleDragCancel
..minFlingDistance = _physics.minFlingDistance
..minFlingVelocity = _physics.minFlingVelocity
..maxFlingVelocity = _physics.maxFlingVelocity
..dragStartBehavior = dragStartBehavior;
},
),
};
break;
}
}
_lastCanDrag = canDrag;
_lastAxisDirection = axis;
_syncAll(_gestureRecognizers);
}