首页 > 解决方案 > 即使使用 singleChildScrollView LIstview.bulder,底部也会溢出

问题描述

我正在尝试在颤振应用程序中实现列表。这是我的身体:

Container(
    padding: EdgeInsets.fromLTRB(35.0, 40.0, 0.0, 0.0),
    child: Column(
      children: <Widget>[
        Text(
          date,
          textAlign: TextAlign.center,
          style: TextStyle(
            fontSize: 30.0,
            color: Colors.teal,
            fontWeight: FontWeight.bold,
            fontFamily: 'Montserrat'),
        ),
        SingleChildScrollView(
          child: ListView.builder(
          scrollDirection: Axis.vertical,
          shrinkWrap: true,
          itemCount: people.length,
          itemBuilder: (BuildContext context, int index){
            return Card(
              color: Colors.white,
              child: Padding(
                padding: EdgeInsets.symmetric(vertical: 4.0, horizontal: 6.0),
                child: Center(
                  child: ListTile(
                    onTap: () => {},
                    title: Text(
                      "Name: "+people[index]['name'],
                      style: TextStyle(
                        color: Colors.teal,
                        fontWeight: FontWeight.bold,
                        fontFamily: 'Montserrat',
                        fontSize: 21
                        ),
                      ),
                    subtitle: Text(
                      "Phone number: "+people[index]['phone'],
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontFamily: 'Montserrat',
                        fontSize: 16
                      ),
                    ),
                  )
                ) 
              ),
            );
            },
        ),
        )  
      ],
    )
),

如您所见,我将其用作身体的根小部件。该容器有一个子列,其中包含一个文本,该文本是页面的标题和一个SingleChildScrollView有助于列表滚动的文本。我期待得到一个可以滚动的列表,但底部被溢出了。任何帮助,将不胜感激。谢谢你。

标签: flutter

解决方案


将 Listview 包装在 Expanded 小部件中

Expanded(
child: ListView.builder()
 )

或使用 Container 并设置高度和宽度


推荐阅读