Flutter 使用 FittedBox对VideoPlayer进行全屏适配,无拉伸

为了实现视频全屏播放,不留黑边不拉伸的效果:

开始的时候我尝试使用下面的代码进行适配,但是直接报错,ViedoPlayer属于Texture,不可以直接包裹在FittedBox下,必须再给VideoPlayer嵌套一层宽高明确的控件。

FittedBox(
                      fit: BoxFit.cover,
                        child: VideoPlayer(controller: _playerControler.getMainController()),
                      ),

最后参考了:Flutter videoplayer适配_kgdtl的博客-CSDN博客

Center(
      child: SizedBox.expand(
             child: FittedBox(
                fit: BoxFit.cover,
                child: SizedBox(
                    height: 16,
                    width: 9,
                    child: VideoPlayer(player.controller)),
              )
));

猜你喜欢

转载自blog.csdn.net/mldxs/article/details/130920223