问题描述
不熟悉,试图制作一个包含长列表视图的可滚动页面。我尝试了在不同的SO页面上阅读的一些不同内容,因此我的代码可能显得肿。我不确定为什么即使页面显示正常,并且显示了最后一个ListTile的图像,我也无法向下滚动屏幕来查看该图像的其余部分。
class About extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.amberAccent,appBar: AppBar(
title: Text('About this App'),backgroundColor: Colors.lightGreen[400],centerTitle: true,),body: SingleChildScrollView(
scrollDirection: Axis.vertical,child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,children: <Widget>[
Text(
'The following people helped made my first app possible:',textAlign: TextAlign.center,style: TextStyle(
fontSize: 20,color: Colors.black,fontWeight: FontWeight.bold)),ListView(
shrinkWrap: true,padding: EdgeInsets.all(15.0),children: <Widget>[
ListTile(
leading: Text('Me'),title: Text(
'a little about myself'),ListTile(
leading: Text('Coworker'),title: Text(
'Contribution made by coworker'),ListTile(
leading: Text('Friend'),title: Text(
'Message about friend'),ListTile(
title: SizedBox(
height: 500.0,width: 500.0,child: Image.asset('images/friend.jpeg')),],])));
}
}```
解决方法
在您的列表视图中,使用physics: ScrollPhysics(),
以获得更详细的答案,请参见下面的链接
How to implement Nested ListView in Flutter?
,问题是您将高度无限的ListView
放入高度有限的Column
小部件内,因此ListView
不知道如何渲染自身
ListView
由于具有滚动功能而具有无限的高度,因此它可以滚动无限量的项目。
Column
的高度是有限的,是屏幕的所有可用高度,因此仅限于该高度。
最简单的解决方案之一是将ListView
包装在Expanded
小部件内以告诉ListView
仅采用所有可用高度,这就是Expanded
小部件
如果将来有人遇到与我相同的问题,这就是我为修复代码所做的事情:
对于子级ListView,请使用参数:
shrinkWrap: true,physics: ClampingScrollPhysics(),