Issue
I only tried this on Dartpad, and the Listview does not scroll! I based the code out on https://flutter.dev/docs/cookbook/lists/long-lists.
My original intention is testing for horizontal scroll, but then I find out that it does not scroll vertically either!
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(
MyApp(
items: List<String>.generate(100, (i) => 'Item $i'),
),
);
}
class MyApp extends StatelessWidget {
final List<String> items;
const MyApp({Key? key, required this.items}) : super(key: key);
@override
Widget build(BuildContext context) {
const title = 'Long List';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: const Text(title),
),
body: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(items[index]),
);
},
),
),
);
}
}
Solution
Just wrap with Scrollbar
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(
MyApp(
items: List<String>.generate(100, (i) => 'Item $i'),
),
);
}
class MyApp extends StatelessWidget {
final List<String> items;
const MyApp({Key? key, required this.items}) : super(key: key);
@override
Widget build(BuildContext context) {
const title = 'Long List';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: const Text(title),
),
body: Scrollbar(
child: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(items[index]),
);
},
),
),
),
);
}
}
Answered By – Nilesh Senta
Answer Checked By – David Goodson (FlutterFixes Volunteer)