How can you “center crop” a Widget in Flutter?

前端 未结 4 631
自闭症患者
自闭症患者 2020-12-29 00:00

I have a VideoPlayer widget that needs to be fullscreen and also fit the aspect ratio of the source video. In order to achieve that, I\'ll need to chop off either the top/bo

4条回答
  •  爱一瞬间的悲伤
    2020-12-29 00:33

    I had a lot of problems with this, and the accepted answer didn't solve it for me. I was just trying to get a background image to fit vertically and overflow horizontally. Here's how I ended up doing it:

    OverflowBox(
        maxWidth: double.infinity,
        alignment: Alignment.center,
        child:
            Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
                UnconstrainedBox(
                    constrainedAxis: Axis.vertical,
                    child: Image.asset('images/menu_photo_1.jpg', fit: BoxFit.cover))
            ])
    )
    

提交回复
热议问题