setCanDrag method

  1. @override
void setCanDrag(
  1. bool canDrag
)

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

Implementation

@override
void setCanDrag(bool canDrag) {
  PlatformDispatcher.instance.views;
  DeviceGestureSettings gestureSettings = DeviceGestureSettings.fromView(currentView);

  // Break no use update drag logic
  if (canDrag == _lastCanDrag &&
      axis == _lastAxisDirection &&
      (canDrag && _gestureRecognizers.keys.isNotEmpty || !canDrag && _gestureRecognizers.keys.isEmpty)) {
    return;
  }
  // Only this case can update to scroll mode,
  // else no scroll mode
  if (canDrag && _overflowType != CSSOverflowType.hidden) {
    switch (axis) {
      case Axis.vertical:
      // Vertical drag gesture recognizer to trigger vertical scroll.
        _gestureRecognizers = <Type, GestureRecognizerFactory>{
          ScrollVerticalDragGestureRecognizer:
          GestureRecognizerFactoryWithHandlers<ScrollVerticalDragGestureRecognizer>(
                () => ScrollVerticalDragGestureRecognizer(supportedDevices: dragDevices),
                (ScrollVerticalDragGestureRecognizer instance) {
              instance
                ..isAcceptedDrag = _isAcceptedVerticalDrag
                ..onDown = _handleDragDown
                ..onStart = _handleDragStart
                ..onUpdate = _handleDragUpdate
                ..onEnd = _handleDragEnd
                ..onCancel = _handleDragCancel
                ..minFlingDistance = _physics.minFlingDistance
                ..minFlingVelocity = _physics.minFlingVelocity
                ..maxFlingVelocity = _physics.maxFlingVelocity
                ..gestureSettings = gestureSettings
                ..dragStartBehavior = dragStartBehavior;
            },
          ),
        };
        break;
      case Axis.horizontal:
      // Horizontal drag gesture recognizer to horizontal vertical scroll.
        _gestureRecognizers = <Type, GestureRecognizerFactory>{
          ScrollHorizontalDragGestureRecognizer:
          GestureRecognizerFactoryWithHandlers<ScrollHorizontalDragGestureRecognizer>(
                () => ScrollHorizontalDragGestureRecognizer(supportedDevices: dragDevices),
                (ScrollHorizontalDragGestureRecognizer instance) {
              instance
                ..isAcceptedDrag = _isAcceptedHorizontalDrag
                ..onDown = _handleDragDown
                ..onStart = _handleDragStart
                ..onUpdate = _handleDragUpdate
                ..onEnd = _handleDragEnd
                ..onCancel = _handleDragCancel
                ..minFlingDistance = _physics.minFlingDistance
                ..minFlingVelocity = _physics.minFlingVelocity
                ..maxFlingVelocity = _physics.maxFlingVelocity
                ..gestureSettings = gestureSettings
                ..dragStartBehavior = dragStartBehavior;
            },
          ),
        };
        break;
    }
  } else {
    _gestureRecognizers = const <Type, GestureRecognizerFactory>{};
  }

  _lastCanDrag = canDrag;
  _lastAxisDirection = axis;
  _syncAll(_gestureRecognizers);
}