我正在创建一个页面,其中包含通过 listview.builder (在未来的构建器中)构建的部分,现在如果我通过用单个子滚动视图包装父容器来让整个页面滚动并禁用 listview 的滚动物理功能,它不会不要滚动到列表的末尾。如果我启用列表视图的滚动,除了列表视图可以单独滚动之外,它不会带来任何变化
这是我的代码
Scaffold(
body: SingleChildScrollView(
child: Container(
height: size.height,
margin: const EdgeInsets.symmetric(horizontal: 25),
decoration: BoxDecoration(
color: isLight ? lightBeigeColor : lightGreyColor,
border: Border.symmetric(vertical: BorderSide(color: blueColor,width: 2))
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
//a number of children widgets
Expanded(
child: FutureBuilder<List<Posts>>(
//fetching data + error handeling code
return ListView.builder(
//technical code
itemBuilder: (context, index) {
return Container(
margin: const EdgeInsets.symmetric(
vertical: 20,horizontal: 10),
padding: const EdgeInsets.all(10),
height: size.height / 2.8,
decoration: BoxDecoration(
color:isLight ? lightBeigeColor : lightGreyColor,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: blueColor,
width: 1.5
)
),
child: Column(
//some widgets in here
),
);
}
);
}
}),
),
],
),
),
),
);
如果父窗口小部件已经在处理滚动,则不需要使用 ListView。您可以使用列小部件。
builder: (context, snapshot) {
return Column(
children: snapshot.data?.map((e) {
return Container();
},).toList()?? [],
);
},
更好的方法是使用 CustomScrollView。