Reputation: 2364
My singleChildScollView won't scroll vertically. I've checked similar questions regarding this problem but none of them sem to work for me. The page fills up with the items, and the homepage button is placed at the bottom...
...so it looks correct, it just doesn't let me scroll.
Scaffold(
body: SingleChildScrollView(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (ctx, index) {
...list of items here...
}
),
),
)
Note in the example code above I have simplified the original widget tree and removed the homepage button.
Upvotes: 2
Views: 6454
Reputation: 115
In order for the SingleChildScrollView
to work, its parent's height should be defined.
You can achieve this by wrapping the SingleChildScrollView
in a Container/SizedBox
, or by wrapping it with the Expanded
widget.
Upvotes: 1
Reputation: 2364
thanks for the help, expecially @Jahidul Islam. I was missing the physics: ScrollPhysics() line!
Upvotes: 0
Reputation: 12585
@james please check it
Scaffold(
body: Stack(
children: [
SingleChildScrollView(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: ScrollPhysics(),
itemCount: 30,
itemBuilder: (ctx, index) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
child: Text("index $index"),
);
}
),
),
Align(
alignment: Alignment.bottomCenter,
child: ElevatedButton(
onPressed: () {Navigator.pop(context);},
child: Text('Homepage'),
),
),
],
),
)
Upvotes: 2
Reputation: 162
There is two steps you can do to use SingleChildScrollView
in a Column
widget
SizedBox
height
to the SizedBox
widgetTry this out :
Scaffold(
body:
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
//set a height
height : MediaQuery.of(context).size.height/5,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (ctx, index) {
...list of items here...
}
),
],
),
),
),
Center(
child: ElevatedButton(
onPressed: () {Navigator.pop(context);},
child: Text('Homepage'),
),
),
],
),
)
Upvotes: 4