Canvas with Scale/Pan in list View. How to disable scroll

517

You can enable/disable the scroll of your ListView using the physics property :

   bool scrollListEnable = true;

      @override
      Widget build(BuildContext context) {
        return Scaffold(
            body: ListView(
          physics: scrollListEnable
              ? AlwaysScrollableScrollPhysics()
              : NeverScrollableScrollPhysics(),
          children: <Widget>[
            Listener(
              onPointerMove: (details) {
                print("onPointerMove : $details");
                if (scrollListEnable) {
                  setState(() {
                    scrollListEnable = false;
                  });
                }
              },
              onPointerUp: (details) {
                print("onPointerUp : $details");
                setState(() {
                  scrollListEnable = true;
                });
              },
              child: Container(
                height: 200.0,
                width: 200.0,
                color: Colors.red,
              ),
            )
          ],
        ));
      }
Share:
517
Никита Иевлев
Author by

Никита Иевлев

Updated on December 08, 2022

Comments

  • Никита Иевлев
    Никита Иевлев over 1 year

    Sorry for my English. Ask if you cant understand something.

    Hello! In general, I have a listView, in it is one of the elements of the gestureDetector, in which the canvas is located. Canvas draws a pattern.

    I need this scheme to increase and "scroll". I have already registered the logic itself and everything works, but! If you start moving in the canvas area up or down, it will not move the canvas, but scroll through the listView. I googled the Internet to the holes, but found nothing. Roughly speaking, I need that when the user moves up / down in the gestureDetector area, all events are sent there, and not sent to the listView (parent component).

    I have such a structure

    ListView (
    ...
        child: GestureDetector(
        ...
           child: ...
                 child: CustomPaint(...))
    )
    

    I tried to set "behavior: HitTestBehavior.translucent" on my gestureDetector, but it's not help.

  • Никита Иевлев
    Никита Иевлев over 5 years
    Yes, but it's general listView. If i do it, i will cant scroll in other screens.
  • diegoveloper
    diegoveloper over 5 years
    what do you need?
  • Никита Иевлев
    Никита Иевлев over 5 years
    So, I need a way to make a canvas like the main thing for a scrolling event. I need to be able to move the image in the canvas, and at the right moment (when, for example, I scroll the enlarged image to the end) switch to scrolling listView
  • Никита Иевлев
    Никита Иевлев over 5 years
    I think it's can help. In my case listView and canvas are in different files, but i tried to add callback or smth like that. I will text after that