Skip to content

Instantly share code, notes, and snippets.

@dhuma1981
Last active January 12, 2021 14:44
Show Gist options
  • Save dhuma1981/a2c25929e9065e7fbb37f2b2b75cb8f3 to your computer and use it in GitHub Desktop.
Save dhuma1981/a2c25929e9065e7fbb37f2b2b75cb8f3 to your computer and use it in GitHub Desktop.
Show scrollbar in ListView
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final ScrollController _scrollController = ScrollController();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Scrollbar(
isAlwaysShown: true,
controller: _scrollController,
child: ListView.builder(
controller: _scrollController,
itemCount: 100,
itemBuilder: (context, index) {
return Card(
child: ListTile(
title: Text("Item: ${index + 1}"),
));
}),
),
),
),
);
}
}
@bryar323
Copy link

thanks bro i just run your codes in my android studio for test, but i get it, after you replay .

@riskiadi
Copy link

riskiadi commented Dec 9, 2020

what is final ScrollController _scrollController = ScrollController(); do ? why we must add that code

@jdebecka
Copy link

You are initializing new ScrollController so then you can pass it to Scrollbar and ListView. You have to pass the same object and that's why it's defined above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment