flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.72k stars 27.37k forks source link

Touch up/down status for slider.dart #32768

Closed jdeltoft closed 1 year ago

jdeltoft commented 5 years ago

I'm using Flutter's Material slider.dart and the official widget supports callbacks for onChanged, onChangeEnd, and onChangeStart. These start and end callbacks are a bit odd though in that they trigger on a quick tap of the slider, as well as a touch and slide of the slider that's still being held, and then they fire again when the slider thumb is released. What I really need to know is when the slider is FULLY released (from either a quick tap OR a touch and slide).

So I have found a way to edit .../flutter/packages/flutter/lib/src/Material/slider.dart in a way that prints out to the console the status I need. I look at all handleEvent calls and added the following to know when touch was up or down (see the change using event.runtimeType):

  @override
  void handleEvent(PointerEvent event, BoxHitTestEntry entry) {
    if (event.runtimeType == PointerDownEvent) {
      _touchActive = true;
      print("---------Down!---------");
    } else if (event.runtimeType == PointerUpEvent) {
      _touchActive = false;
      print("---------Up!---------");
    }
    assert(debugHandleEvent(event, entry));
    if (event is PointerDownEvent && isInteractive) {
      // We need to add the drag first so that it has priority.
      _drag.addPointer(event);
      _tap.addPointer(event);
    }
  }

But now I need to somehow get that data back out of the widget through a callback. The callback can be similar to any of the three mentioned earlier such as onChangeStart or onChangeEnd, but I'm not sure where all I need to update to create this. Can anyone help point me to how to add this?

TahaTesser commented 1 year ago

Hi

This seems to be no longer reproducible, onChangeStart and onChangeEnd are firing as expected, tried on mobile and desktop with tap and drag.

Given the start and end callbacks work as expected, getting touch up/down status is not really required or matching the specs.

Given there is no odd behavior and the lack of activity on this issue, I feel safe to close this.

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.