Reputation: 19184
I am developing for Windows desktop, using Flutter 2.0. Scrolling lists using the mouse wheel is somehow boring, how can I add items per wheel-tick settings?
Upvotes: 4
Views: 1216
Reputation: 3630
I had the same issue and here is the workaround I've found.
In your widget, where you have your scrolling element (could be a list, or, in my case, a SingleChildScrollView
), add a ScrollController
and add a listener to it:
class ScrollViewTest extends StatelessWidget
{
static const _extraScrollSpeed = 80; // your "extra" scroll speed
final ScrollController _scrollController = ScrollController();
// Constructor.
ScrollViewTest({Key? key}) : super(key: key)
{
_scrollController.addListener(() {
ScrollDirection scrollDirection = _scrollController.position.userScrollDirection;
if (scrollDirection != ScrollDirection.idle)
{
double scrollEnd = _scrollController.offset + (scrollDirection == ScrollDirection.reverse
? _extraScrollSpeed
: -_extraScrollSpeed);
scrollEnd = min(
_scrollController.position.maxScrollExtent,
max(_scrollController.position.minScrollExtent, scrollEnd));
_scrollController.jumpTo(scrollEnd);
}
});
}
@override
Widget build(BuildContext context)
{
return SingleChildScrollView(
controller: _scrollController,
child: Container(...),
);
}
}
Upvotes: 3