setCanDrag method

  1. @override
  2. @protected
void setCanDrag(
  1. bool value
)
override

Whether the user can drag the widget, for example to initiate a scroll.

Implementation

@override
@protected
void setCanDrag(bool value) {
  if (value == _lastCanDrag && (!value || widget.axis == _lastAxisDirection)) {
    return;
  }
  if (!value) {
    _gestureRecognizers = const <Type, GestureRecognizerFactory>{};
    // Cancel the active hold/drag (if any) because the gesture recognizers
    // will soon be disposed by our RawGestureDetector, and we won't be
    // receiving pointer up events to cancel the hold/drag.
    _handleDragCancel();
  } else {
    switch (widget.axis) {
      case Axis.vertical:
        _gestureRecognizers = <Type, GestureRecognizerFactory>{
          VerticalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<VerticalDragGestureRecognizer>(
            () => VerticalDragGestureRecognizer(supportedDevices: _configuration.dragDevices),
            (VerticalDragGestureRecognizer instance) {
              instance
                ..onDown = _handleDragDown
                ..onStart = _handleDragStart
                ..onUpdate = _handleDragUpdate
                ..onEnd = _handleDragEnd
                ..onCancel = _handleDragCancel
                ..minFlingDistance = _physics?.minFlingDistance
                ..minFlingVelocity = _physics?.minFlingVelocity
                ..maxFlingVelocity = _physics?.maxFlingVelocity
                ..velocityTrackerBuilder = _configuration.velocityTrackerBuilder(context)
                ..dragStartBehavior = widget.dragStartBehavior
                ..multitouchDragStrategy = _configuration.getMultitouchDragStrategy(context)
                ..gestureSettings = _mediaQueryGestureSettings
                ..supportedDevices = _configuration.dragDevices;
            },
          ),
        };
      case Axis.horizontal:
        _gestureRecognizers = <Type, GestureRecognizerFactory>{
          HorizontalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<HorizontalDragGestureRecognizer>(
            () => HorizontalDragGestureRecognizer(supportedDevices: _configuration.dragDevices),
            (HorizontalDragGestureRecognizer instance) {
              instance
                ..onDown = _handleDragDown
                ..onStart = _handleDragStart
                ..onUpdate = _handleDragUpdate
                ..onEnd = _handleDragEnd
                ..onCancel = _handleDragCancel
                ..minFlingDistance = _physics?.minFlingDistance
                ..minFlingVelocity = _physics?.minFlingVelocity
                ..maxFlingVelocity = _physics?.maxFlingVelocity
                ..velocityTrackerBuilder = _configuration.velocityTrackerBuilder(context)
                ..dragStartBehavior = widget.dragStartBehavior
                ..multitouchDragStrategy = _configuration.getMultitouchDragStrategy(context)
                ..gestureSettings = _mediaQueryGestureSettings
                ..supportedDevices = _configuration.dragDevices;
            },
          ),
        };
    }
  }
  _lastCanDrag = value;
  _lastAxisDirection = widget.axis;
  if (_gestureDetectorKey.currentState != null) {
    _gestureDetectorKey.currentState!.replaceGestureRecognizers(_gestureRecognizers);
  }
}