3

Is it possible to disable scroll in certain areas of a scrollable widget?

Lets say I want to disable scroll within a square area in the middle of the ListView/CustomScrollView, is that possible?

I am thinking it might require me to pass true or false in some touch hitTest or some similar concept but I am not sure where to start. Any ideas?

  • It's not possible to disable scroll in certain areas of a scrollable widget, but you can achieve a similar effect by wrapping the area you want to disable scrolling for in a non-scrollable widget, such as a Container. This will prevent the user from being able to scroll in that area, while allowing them to continue scrolling in the rest of the scrollable widget. – Yahor Barkouski Dec 04 '22 at 17:37
  • @Begging Is there a non Stack way of doing this? For example, if I have a List with many items but I don't want the scroll of the list to happen if the touch is in the area of the 4th item in the list? – sudoExclaimationExclaimation Dec 04 '22 at 23:00

1 Answers1

0

You can use the Stack widget to overlay an AbsorbPointer widget on top of your scrollable:

 return Scaffold(
      body: Stack(
        children: [
          CustomScrollView(
            slivers: [
              SliverList(
                delegate: SliverChildBuilderDelegate(
                  (BuildContext context, int index) {
                    return Text('...');
                  },
                  childCount: 200,
                ),
              ),
              // Rest of the list
            ],
          ),
          Positioned.fill(
            child: Center(
              child: AbsorbPointer(
                absorbing: true,
                child: Container(
                  width: 100,
                  height: 100,
                  color: Colors.blue,
                ),
              ),
            ),
          ),
        ],
      ),
    );
Code on the Rocks
  • 11,488
  • 3
  • 53
  • 61
  • 1
    Is there a non Stack way of doing this? For example, if I have a List with many items but I don't want the scroll of the list to happen if the touch is in the area of the 4th item in the list? – sudoExclaimationExclaimation Dec 04 '22 at 22:59