StaggeredGridView 的动态高度在 flutter 项目中不起作用

Dynamic height for StaggeredGridView is not working in flutter project

我想构建一个 StaggeredGridView,在第 0 个索引处有一个横幅视频,每行有 2 张卡片。但是视频没有填满屏幕宽度,因为每一行的高度都是一样的。

这是我正在做的。

static final videoPlayerController = VideoPlayerController.network(
  "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4");

static final chewieController = ChewieController(
videoPlayerController: videoPlayerController,
aspectRatio: 3 / 2,
autoPlay: true,
looping: true,
allowMuting: true,
allowFullScreen: false,);

final playerWidget = Chewie(
controller: chewieController,);

构建小部件的代码:

Widget buildStaggeredListing(BuildContext context) {
return StaggeredGridView.countBuilder(
  crossAxisCount: 2,
  crossAxisSpacing: 4.0,
  itemCount: 10,
  itemBuilder: (BuildContext buildContext, int index) {
    if (index == 0) {
      return playerWidget;
    }
    return Card(
      child: Padding(
        padding: EdgeInsets.all(16.0),
        child: Text(
          index.toString(),
          style: TextStyle(fontSize: 22.0),
        ),
      ),
    );
  },
  staggeredTileBuilder: (int index) {
    if (index == 0) {
      return StaggeredTile.count(2, 1);
    }
    return StaggeredTile.count(1, 1);
  },
);

}

截图:screenshot

更新:根据sagar acharya的回答,我使用了

if (index == 0) {
      return StaggeredTile.fit(1);
   }
    return StaggeredTile.fit(2);

这就是正在发生的事情:screenshot2

只需检查此代码是否有效:

staggeredTileBuilder: (int index) {
    if (index == 0) {
      return StaggeredTile.fit(2);
    }
    return StaggeredTile.count(1,1);
  },