【问题标题】:how to fit cover videos in flutter如何在颤动中适应封面视频
【发布时间】:2022-12-14 20:29:26
【问题描述】:

我试图制作一个带有视频的容器,但当然不可能将完整的视频放入尺寸容器中,我尝试使用 fit,但甚至有错误,所以我尝试使用剪辑,这里是谁想要的解决方案:

如果有办法使用合适的封面,有人吗???

代码夹在这里:它工作正常:

ClipRect(
        clipBehavior: Clip.hardEdge,
        child: Container(
          width: double.infinity, \\ another size
          height: 400, \\another size
          alignment: Alignment.center,
          child: Transform.scale( scale: 2,
            child: AspectRatio( aspectRatio: _controller!.value.aspectRatio,
                child: VideoPlayer(_controller as VideoPlayerController)
            ),
          ),
        ),
      ),

【问题讨论】:

    标签: android flutter video scale clip


    【解决方案1】:

    使用 FittedBox 小部件,您可以调整任何子小部件的大小以适应容器:

    Container(
      width: 500,
      height: 300,
      child: FittedBox(
        fit: BoxFit.cover,
        child: AspectRatio( 
          aspectRatio: _controller!.value.aspectRatio,
          child: VideoPlayer(_controller as VideoPlayerController),
        ),
      ),
    ),
    

    【讨论】:

    • 所以,就这样,我试了很多次,都报错了!你已经测试过了吗?
    • 错误是什么?
    【解决方案2】:

    试试看,对我有用

    SizedBox.expand(
      child: FittedBox(
        alignment: Alignment.center,
        fit: BoxFit.cover,
        child: SizedBox(
          height: _controller.value.size.height,
          width: _controller.value.size.width,
          child: VideoPlayer(
            _controller,
          ),
        ),
      ),
    ),
    

    【讨论】:

      猜你喜欢
      • 2021-09-03
      • 1970-01-01
      • 2022-06-21
      • 2013-09-02
      • 1970-01-01
      • 1970-01-01
      • 2022-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多