dart 约束,具有限制高度':不是真正的Flutter

ht4b089n  于 2022-12-15  发布在  Flutter
关注(0)|答案(4)|浏览(134)

我正在堆叠小部件,希望它可以滚动,因此我使用了列表视图,但遇到了此错误(constraints. hasBoundedHeight ':不是真正的flutter)我看到列表视图不能放在列表视图里面,所以我把它改为列,但我仍然得到同样的错误。下面是我的代码。谢谢。

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;}
yi0zb3m4

yi0zb3m41#

对于我来说,我的工作就是用一个容器 Package CustomScrollView或ListView。

Container(
                margin: EdgeInsets.all(5.0),
                height: 295.0,
                width: 333.0,
                child: CustomScrollView(),
              ),
fnx2tebb

fnx2tebb2#

所以我最终解决了这个特殊方法的问题,方法如下:
1.将FutureBuilder封装在容器中;
1.给定容器的宽度和高度;
1.将其添加到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),
                      ),
                    ],
                  );
                },
              );
            }
          },
        ),   
      ); 
    }
imzjd6km

imzjd6km3#

使用容器 Package 内部列表视图并给予高度。

e4yzc0pl

e4yzc0pl4#

SizedBox小部件 Package GridView小部件,并给予heightwidth值,如下所示:

SizedBox(
  height: 100,
  width: double.infinity, // (double.infinity) to fill screen width
  child: GridView.count(
    // your GridView code ...
  ),
);

相关问题