I have a screen with Text widgets and ListView, and when I try to scroll inside the ListView, it doesn't allow me to scroll.
My body is SingleChildScrollView but that doesn't provide scrollView for the ListView.builder. I tried to wrap the ListView.build inside Expanded, but didn't work out.
class HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: Text("MyBar"),
centerTitle: true,
),
body: SingleChildScrollView(child: Column(
children: <Widget>[
Text(
"Information"),
Container(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: widget.match.players.length,
itemBuilder: (context, index) {
return Column(
children: <Widget>[
Card(
child: ListTile(
leading: CircleAvatar(
radius: 30.0,
foregroundColor:
Theme.of(context).primaryColor,
backgroundColor: Colors.grey,
backgroundImage:
CachedNetworkImageProvider("url"),
),
title: new Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
new Text("Some text",
style: new TextStyle(
fontWeight: FontWeight.bold),
),
new Text(
"Some text",
style: new TextStyle(
fontWeight: FontWeight.bold),
),
]),
))
],
);
}))
],
)));}
}
Anyone has an idea how I can make the listView.builder() scrollable.
ListView is the most commonly used scrolling widget. It displays its children one after another in the scroll direction. In the cross axis, the children are required to fill the ListView. If non-null, the itemExtent forces the children to have the given extent in the scroll direction.
You can make the ListView widget never scrollable by setting physics property to NeverScrollableScrollPhysics().
All you have to do is set Global Keys for your widgets and call Scrollable. ensureVisible on the key of your widget you want to scroll to. For this to work your ListView should be a finite List of objects.
To scroll a Flutter ListView widget horizontally, set scrollDirection property of the ListView widget to Axis. horizontal. This arranges the items side by side horzontally. Following is the basic syntax to arrange the items horizontally in a ListView and scroll them horizontally.
You need to make the ListView.builder
not scrollable so the SingleChildScrollView
can scroll. You could achieve that by setting one of these two properties to the ListView.builder
:
physics: NeverScrollableScrollPhysics()
or
primary: false
But using the ListView.builder
the way you're using it, it will create all the items at once. If you want to use the ListView.builder
efficiently to create the items only when they're scrolled onto the screen, you could remove the SingleChildScrollView
and just use ListView.builder
like this:
ListView.builder(
itemCount: widget.match.players.length + 1,
itemBuilder: (context, index) {
if (index == 0) {
return Text("Information");
}
int listIndex = index - 1;
// then you could use: widget.match.players[listIndex];
return Column(...);
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With