I have tried the interactive example of the Flutter API documentation about CustomScrollView widget (https://api.flutter.dev/flutter/widgets/CustomScrollView-class.html) but simply adding the property scrollDirection: Axis.horizontal to show the items like columns, and the scroll with the mouse doesn’t work in the web navigator when I have many items added.
The code:
import 'package:flutter/material.dart';
/// Flutter code sample for [CustomScrollView].
void main() => runApp(const CustomScrollViewExampleApp());
class CustomScrollViewExampleApp extends StatelessWidget {
const CustomScrollViewExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: CustomScrollViewExample(),
);
}
}
class CustomScrollViewExample extends StatefulWidget {
const CustomScrollViewExample({super.key});
@override
State<CustomScrollViewExample> createState() =>
_CustomScrollViewExampleState();
}
class _CustomScrollViewExampleState extends State<CustomScrollViewExample> {
List<int> top = <int>[];
List<int> bottom = <int>[0];
@override
Widget build(BuildContext context) {
const Key centerKey = ValueKey<String>('bottom-sliver-list');
return Scaffold(
appBar: AppBar(
title: const Text('Press on the plus to add items above and below'),
leading: IconButton(
icon: const Icon(Icons.add),
onPressed: () {
setState(() {
top.add(-top.length - 1);
bottom.add(bottom.length);
});
},
),
),
body: CustomScrollView(
center: centerKey,
scrollDirection: Axis.horizontal, // <-- I HAVE ADDED THIS AND IT DOESN'T SCROLL
slivers: <Widget>[
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
alignment: Alignment.center,
color: Colors.blue[200 + top[index] % 4 * 100],
height: 100 + top[index] % 4 * 20.0,
child: Text('Item: ${top[index]}'),
);
},
childCount: top.length,
),
),
SliverList(
key: centerKey,
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
alignment: Alignment.center,
color: Colors.blue[200 + bottom[index] % 4 * 100],
height: 100 + bottom[index] % 4 * 20.0,
child: Text('Item: ${bottom[index]}'),
);
},
childCount: bottom.length,
),
),
],
),
);
}
}
I expected that it could be scrollable horizontally with the mouse, like with the default vertical behavior of the documentation example, but it doesn’t. Any suggestions?