本文介绍了Constraints.hasBoundedHeight':不是真正的颤动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在堆叠小部件,并且希望它可以滚动,所以我使用了列表视图,并且遇到了此错误(constraints.hasBoundedHeight':不是真正的颤动),我看到某个地方无法将列表视图放置在列表视图中,所以我进行了更改它到列,但我仍然遇到相同的错误。下面是我的代码。

I am stacking widgets and i want it to be scrollable so i used a listview and i am getting this error (constraints.hasBoundedHeight': is not true flutter) i saw somewhere that listview cannot be placed inside a listview so i changed it to Column but i still got the same error. Below is my Code. Thanks.

ListView homeList(){
var listView = ListView(
  shrinkWrap: true,
  children: <Widget>[
    _imageSlider(),

    Padding(
      padding: EdgeInsets.only(top: 15.0, bottom: 15.0, left: 15.0),
      child: Text("Trending", style: TextStyle(color: Colors.white, fontSize: 15.0),),
    ),

   Container(
     child: FutureBuilder(
       future: _trendingListImages(),
         builder: (BuildContext context, AsyncSnapshot async){
           if(async.data == null){
           return ColorLoader3(
          radius: 20.0,
          dotRadius: 5.0,
           );
          }else{
            return ListView.builder(
                shrinkWrap: true,
                scrollDirection: Axis.horizontal,
                itemCount: async.data.length,
                itemBuilder: (BuildContext context, int position) {
                  return Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Card(
                        elevation: 18.0,
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.all(Radius.circular(10.0))),
                        child: Image.network(
                          "http://image.tmdb.org/t/p/w500/"+async.data[position].backdropPath,
                          fit: BoxFit.cover,
                          height: 200.0,
                          width: 130.0,
                        ),
                        clipBehavior: Clip.antiAlias,
                        margin: EdgeInsets.all(8.0),
                      ),
                      Text(
                        async.data[position].title,
                        style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
                      )
                    ],
                  );
                });
           }
         }
     ),
   )
  ],
);

return listView;}


推荐答案

因此,我通过执行以下操作终于解决了此特定方法的问题:

So I finally solved the problem of this particular method by doing the following:


  1. 封闭 FutureBuilder 放在容器中;

  2. 给出容器的宽度和高度;

  3. 将其添加到 ListView

  1. enclosing the FutureBuilder in a container;
  2. giving the container width and height;
  3. adding it to a ListView.

这是代码:

    Widget _featuredListHorizontal() {   
      return Container(
        margin: const EdgeInsets.symmetric(vertical: 20.0),
        height: 300.0,
        child: FutureBuilder(
          future: _trendingListImages(),
          builder: (BuildContext context, AsyncSnapshot listData) {
            if (listData == null) {
              return ColorLoader3(
                radius: 20.0,
                dotRadius: 5.0,
              );
            } else {
              return ListView.builder(
                shrinkWrap: true,
                physics: ClampingScrollPhysics(),
                scrollDirection: Axis.horizontal,
                itemCount: listData.data.length,
                itemBuilder: (BuildContext context, int position) {
                  return Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Card(
                        elevation: 18.0,
                        shape: const RoundedRectangleBorder(
                            borderRadius:
                            BorderRadius.all(Radius.circular(10.0))),
                        clipBehavior: Clip.antiAlias,
                        margin: const EdgeInsets.all(8.0),
                        child: Image.network(
                          "http://image.tmdb.org/t/p/w500/${listData.data[position].backdropPath}",
                          fit: BoxFit.cover,
                          height: 200.0,
                          width: 230.0,
                        ),
                      ),
                      Text(
                        listData.data[position].title,
                        style: TextStyle(
                            fontSize: 12.0,
                            fontWeight: FontWeight.bold,
                            color: Colors.white),
                      ),
                    ],
                  );
                },
              );
            }
          },
        ),   
      ); 
    }

这篇关于Constraints.hasBoundedHeight':不是真正的颤动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 08:42