I have a list view that I want to make scrollable inside a container. However, when I scroll down and release my finger, the list locks back to the top. I tried wrapping the list view in a SingleChildScrollView, but it didn’t work. Here’s the relevant code:
// The container that holds the list view
SizedBox(
height: 501,
child: SingleChildScrollView(
child: Column(
children: [
// A button to add a new item to the list
TextButton.icon(
onPressed: () { ... },
icon: Icon(Icons.add),
label: Text("Add Course"),
),
// The list view that needs to be scrollable
ListView.builder(
shrinkWrap: true,
itemCount: ...,
itemBuilder: (context, index) { ... },
),
],
),
),
);
2
Answers
You are using scroll twice.
If you want to scroll the
ListView
only, remove theSingleChildScrollView
. You need to stop one of them. if you want to scroll theListview.builder
andButton
together, addprimary : false
to Listview.builder:You can get more information about
primary
property here:https://api.flutter.dev/flutter/widgets/ScrollView/primary.html