我的可滚动列表视图有什么问题?

问题描述

不熟悉,试图制作一个包含长列表视图的可滚动页面。我尝试了在不同的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(),

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...