我正在构建一个列表视图来显示视频.我正在使用列表视图来显示每个博客文章的2个视频. 我已经将ListView包装在一个自定义高度和宽度的SizedBox中.对于前2篇博客文章,2个视频显示正确,但当我向下滚动到第三篇博客文章时,我得到:

BoxConstraints强制无限高:导致小部件的相关错误为 SizedBox.Expand().

呈现博客文章的页面本身由于内存不足错误而冻结并崩溃.我必须重新运行调试.

以下是我的代码:

Widget _buildVideoPlayerListTwo(
      {List<PostMedia>? mediaItems,
      double? width,
      double? height,
      Post? post}) {
    return SizedBox(
      height: widget.height,
      width: widget.width,
      child: ListView.builder(
          scrollDirection: Axis.horizontal,
          physics: const PageScrollPhysics(),
          padding: EdgeInsets.zero,
          shrinkWrap: true,
          itemCount: mediaItems!.length,
          itemExtent: 186,
          itemBuilder: (context, index) {
            return Stack(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.only(left: 2, right: 2),
                  child: ClipRRect(
                    borderRadius: const BorderRadius.only(
                        topLeft: Radius.circular(6),
                        topRight: Radius.circular(6),
                        bottomLeft: Radius.circular(6),
                        bottomRight: Radius.circular(6)),
                    child: SizedBox.expand(
                      child: FittedBox(
                        fit: BoxFit.cover,
                        child: SizedBox(
                          height: widget.height,
                          width: widget.width,
                          child: KNVideoPlayer(
                            videoUrl:
                                mediaItems[index].contentObject.file.toString(),
                            thumbnailUrl: mediaItems[index]
                                .contentObject
                                .thumbnail
                                .toString(),
                            isConstrained: widget.isConstrained,
                            controller: _knVideoPlayerController,
                          ),
                        ),
                      ),
                    ),
                  ),
                )
              ],
            );
          }),
    );
  }

推荐答案

You can't let the SizedBox expand while it's inside a scroll view.

父SizedBox约束:

return SizedBox(
  height: widget.height,
  width: widget.width,
  child: ListView.builder(

而你的树叶却有videoPlayer个禁忌:

 child: SizedBox(
                          height: widget.height,
                          width: widget.width,
                          child: KNVideoPlayer(

在所有情况下,视频分配整个屏幕,what is the purpose of expanded sized box ?

我认为你的问题是让视频覆盖屏幕,而不是被包含!

如果是这样,请try 删除Expnded SiizedBox,并将视频播放器包装为合适的盒子:

 child: SizedBox
                 height: widget.height,
                 width: widget.width,
                          child: FittedBox -----> cover--> KNVideoPlayer(

希望能帮上忙.

Flutter相关问答推荐

如何使用底部导航栏修复此导航问题

Flutter 中的面向对象模式

如何使用flutter_local_notification包处理通知操作?

try 使用fl_Chart of Ffltter,但在导入它时遇到以下错误:Error:';TextScaler';is;t a type

Flutter 数独网格

使用 forLoops 在 Dart 中进行单元测试会返回 stackoverflow

Flutter屏幕适配 - 在模拟器和真实手机上文本尺寸不同

Flutter blue plus 库,当try 从 esp32 驱动程序获取 PlatformException 时读取特性

MediaQuery 在不同手机上不一致

Flutter可滚动定位列表支持rtl方向吗?

如何在 Flutter 中测试动画图标

为什么 appBar 小部件在 flutter 中不是常量

如何修复 ICU Lexing 错误:Flutter 中的意外字符

如何在 flutter 的alert 对话框中实现进度指示器?

Flutter 如何要求用户在应用程序中设置电话密码?

使用 Chaquopy 插件后 Gradle Sync 无法正常工作

如何在dart中编写多个条件?

在 Flutter 中,如何使用文本字段和方形图像进行行布局

如何从用户 Flutter 导航抽屉中隐藏管理菜单

Flutter:如何将 AssetImage 转换为 Unit8List?