Flutter - How to prevent ScrollView scroll when I drag a slider on it?

ε祈祈猫儿з 提交于 2021-01-29 13:54:08

问题


I put a slider on a CustomScollView, When I drag the slider, the scrollview will scroll up and down slightly, so my question is When I drag the slider, how to fibidden scroll of the scrollview?

This slider is custom slider which extends RenderConstrainedBox

class _RenderCupertinoSlider extends RenderConstrainedBox {
  _RenderCupertinoSlider(){
    _drag = new HorizontalDragGestureRecognizer()
      ..onStart = _handleDragStart
      ..onUpdate = _handleDragUpdate
      ..onEnd = _handleDragEnd;
  }
    HorizontalDragGestureRecognizer _drag; 
   
    @override
  bool hitTestSelf(Offset position) {
    print("hitTestSelf");
    if ((position.dx - _minThumbCenter).abs() < Circle_Radius + _kPadding) {
      pickedThumb = _kMinThumb; // _kMinThumb = 1
      print("hitTestSelf true");
      return true;
    }

    if ((position.dx - _maxThumbCenter).abs() < Circle_Radius + _kPadding) {
      pickedThumb = _kMaxThumb; // _kMaxThumb = 2
      return true;
    }

    return false;
  }

  @override
  void handleEvent(PointerEvent event, BoxHitTestEntry entry) {
    assert(debugHandleEvent(event, entry));
    if (event is PointerDownEvent) _drag.addPointer(event);
  }

}

来源:https://stackoverflow.com/questions/62759601/flutter-how-to-prevent-scrollview-scroll-when-i-drag-a-slider-on-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!