[英]Flutter listview scrolling is not available
I can see 6 list items in my listview widget and I can not scroll the listview although 3 more items are there.我可以在我的列表视图小部件中看到 6 个列表项,尽管还有 3 个项目,但我无法滚动列表视图。
Actually I want to keep this workouts page pretty simple that means I want to avoid using many rows/columns...实际上我想让这个锻炼页面非常简单,这意味着我想避免使用很多行/列......
I have just a text label at the top left corner and below listview.我在左上角和列表视图下方只有一个文本 label。
What do I have to change to make the listview scrolling?我必须改变什么才能使列表视图滚动?
I already use physics: AlwaysScrollableScrollPhysics(),我已经使用物理:AlwaysScrollableScrollPhysics(),
appBar: AppBar(
title: Text(title),
),
body: Container(
color: Colors.green,
margin: const EdgeInsets.all(5.0),
child: Column(
children: [
Align(
alignment: Alignment.topLeft,
child: Text("Workouts", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25)),
),
Expanded(
child: ListView.builder(
physics: AlwaysScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: workouts.length,
itemBuilder: (context, index) {
var workout = workouts[index];
return WorkoutWidget(key: Key(workout.id.toString()), workout: workout);
}),
),
],
),
),
Change physics to NeverScrollableScrollPhysics()
, then wrap your Container
with SingleChildScrollView
widget.将物理更改为NeverScrollableScrollPhysics()
,然后使用SingleChildScrollView
小部件包装您的Container
。 You could also omit scrollDirection
, because Axis.vertical
is already the default value.您也可以省略scrollDirection
,因为Axis.vertical
已经是默认值。
appBar: AppBar(
title: Text(title),
),
body: SingleChildScrollView(
child: Container(
color: Colors.green,
margin: const EdgeInsets.all(5.0),
child: Column(
children: [
Align(
alignment: Alignment.topLeft,
child: Text(
"Workouts",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25),
),
),
Expanded(
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: workouts.length,
itemBuilder: (context, index) {
var workout = workouts[index];
return WorkoutWidget(
key: Key(workout.id.toString()),
workout: workout,
);
}),
),
],
),
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.