I have created some items in SingleChildScrollView
and the problem is that none of the items are scrolled in horizontal mode, but the same code scrolls the items in vertical mode.
Items are scrollable when scrollDirection: Axis.vertical
It can be scrolled horizontally on the Android platform, but it cannot be scrolled on the web and Windows form.
Scaffold(
appBar: CustomAppBar(),
body: RawScrollbar(
thumbVisibility: true,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
physics: AlwaysScrollableScrollPhysics(),
child: Row(
children: List.generate(
50,
(index) => Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 50,
color: Colors.blue,
child: Center(child: Text('Item $index'))),
)),
),
),
));
2
Answers
To make your items scrollable horizontally across all platforms (including web and desktop), you can use
ScrollConfiguration
.The problem occurs because, on platforms like the web and Windows, the default behavior may only listen for specific input types. By explicitly specifying the devices that can control the scroll, you ensure it works across various platforms.
Here’s how you can adjust your code:
Bonus Tip: To enable scrolling using the scroll thumb (the scrollbar handle), you can define a
ScrollController
and set it for both theRawScrollbar
and theSingleChildScrollView
.