Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable drag scrolling but keep mouse wheel scrolling for ListView in Flutter MacOS?

Tags:

flutter

So when I set physics: const NeverScrollableScrollPhysics() on ListView.builder, it also disables mouse wheel scrolling. Is there a way to keep mouse wheel but disable drag?

Thanks

like image 711
widgetycrank Avatar asked Jun 21 '20 03:06

widgetycrank


People also ask

How to get my mouse to stop scrolling?

[Solution] How to Get My Mouse to Stop Scrolling 1 Press Win + I at the same time to open the Windows Settings interface. 2 Navigate to Devices > Mouse. 3 Disable the option of Scroll inactive windows when I hover over them. See More....

What does the mouse scroll button do in gaming?

The scroll button of a mouse can be used to scroll through a long document or webpage. Also, during a game, it can be used as a third button. However, the mouse scroll doesn’t always work well and you may encounter some issues. In our previous post - What to Do If Your Mouse Scroll Wheel Jumps in Windows 10, we show the issue of scroll jumping.

How to fix the Windows 10 scrolling bug?

This is a useful solution to fix the Windows 10 scrolling bug. Just follow these steps below: Step 1: Press Win + I at the same time to open the Windows Settings interface. Step 2: Navigate to Devices > Mouse. Step 3: Disable the option of Scroll inactive windows when I hover over them.

Why does my scroll button start infinite scrolling Windows 10?

When the scroll button starts infinite scrolling, you cannot use the mouse properly. But don’t worry and this is mainly caused by the setting issues. You can easily fix the Windows 10 uncontrollable scrolling.


1 Answers

Thanks for the answer (@HasilT), it helped! I found that PointerScrollEvent.scrollDelta is already "animated", and you can use it with ScrollController.jumpTo. In my code, I prevent overscroll with min and max functions.

import 'dart:math' as math;

Listener(
  onPointerSignal: (ps) {
    if (ps is PointerScrollEvent) {
      final newOffset = _controller.offset + ps.scrollDelta.dy;
      if (ps.scrollDelta.dy.isNegative) {
        _controller.jumpTo(math.max(0, newOffset));
      } else {
        _controller
            .jumpTo(math.min(_controller.position.maxScrollExtent, newOffset));
      }
    }
  },
  child: ListView.builder(
    itemCount: 100,
    controller: _controller,
    physics: NeverScrollableScrollPhysics(),
    itemBuilder: (BuildContext context, int index) {
      return Container(
          height: 100,
          margin: EdgeInsets.all(10),
          color: index.isEven ? Colors.blue : Colors.green);
    },
  ),
);
like image 138
mhrst Avatar answered Oct 30 '22 05:10

mhrst