扑中的列内的ListViewBuilder

时间:2019-10-08 13:31:18

标签: flutter

我试图将listview.builder包装在该列中,我以这个警告结尾。

I/flutter (22491): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (22491): The following assertion was thrown during performLayout():
I/flutter (22491): RenderFlex children have non-zero flex but incoming height constraints are unbounded.
I/flutter (22491): When a column is in a parent that does not provide a finite height constraint, for example, if it is
I/flutter (22491): in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a
I/flutter (22491): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
I/flutter (22491): space in the vertical direction.

如果高度是有界的,它将在该区域内滚动,而我希望根据列表滚动相应的高度。

  Widget _getSections() {
    double width = MediaQuery.of(context).size.width;
    double height = MediaQuery.of(context).size.height;
    return Container(
      width: width,
//      height: height / 4, /// commented height here
      child: Column(
        children: <Widget>[
          SizedBox(height: 10),
          Expanded(
            flex: 1,
            child: LayoutBuilder(
              builder: (BuildContext c, BoxConstraints constraints) {
                return videoList.isEmpty
                    ? Center(child: Container(child: Text("No records found!", style: TextStyle(fontSize: 16))))
                    : ListView.builder(
                        shrinkWrap: true,
                        itemCount: videoList.length,
                        itemBuilder: (BuildContext context, int index) {
                          return _eachItem(videoList[index]);
                        });
              },
            ),
          ),
          SizedBox(height: 5),
        ],
      ),
    );
  }

EachItem小部件就像

  Widget _eachItem(SongVideos item) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(0.0, 0.5, 0.0, 0.5),
      child: Container(
        child: Padding(
          padding: const EdgeInsets.fromLTRB(16.0, 0.0, 16.0, 16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Text(item.channelTitle, style: TextStyle(color: Colors.black38, fontWeight: FontWeight.w500, fontSize: 16.0)),
              Padding(
                padding: const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 12.0),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Flexible(flex: 3, child: Text(item.title, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18.0))),
                    Flexible(flex: 1, child: Container(height: 60.0, width: 80.0, child: Image.network(item.imageUrl, fit: BoxFit.cover))),
                  ],
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Text(item.getArtistList(), style: TextStyle(color: Colors.black54, fontWeight: FontWeight.w600, fontSize: 14.0)),
                      Text(item.getPlayTime(), style: TextStyle(color: Colors.black45, fontWeight: FontWeight.w500, fontSize: 14.0))
                    ],
                  ),
                  Icon(Icons.bookmark_border),
                ],
              ),
              SizedBox(height: 10),
              Divider(endIndent: 7)
            ],
          ),
        ),
      ),
    );
  }

页面滚动中是否可以有多个列表视图构建器,它们都根据其视图大小或生成的列表高度进行扩展?

0 个答案:

没有答案