如何在Flutter Web中设置VideoPlayer的宽度和高度

r7xajy2e  于 2023-10-22  发布在  Flutter
关注(0)|答案(1)|浏览(176)

我正在使用VideoPlayer播放上传到我网站的.mp4视频。我设置了高度和宽度,它在Android中工作正常,但在Flutter Web中,宽度与容器的宽度不匹配。

Container(//      
      alignment: Alignment.center,
      margin: const EdgeInsets.only(top: 20),
      height: 130,
      width: MediaQuery.of(context).size.width,
      decoration: BoxDecoration(
         borderRadius: BorderRadius.circular(8.0),
         color: Colors.black12, border: 
         Border.all(color: Colors.black)),
      child: SizedBox(width: double.infinity,
          child: ClipRRect(borderRadius:  
          BorderRadius.circular(8), 
          child: VideoPlayer(HomePage._controller1)
      )
     )
    ),

我需要一些技巧,使我的视频全宽或适合它的父母.

xzv2uavs

xzv2uavs1#

我更喜欢使用AZERRATION。

/// use on parent widget, the place you like to get width, 
/// most likely I prefer on Scaffold's body 
/// and then removing subtract the padding from maxWidth 
LayoutBuilder( 
  builder: (context, constraints) {
    final width = constraints.maxWidth;

    return AspectRatio(
      aspectRatio: width < 600 ? 1.5 : 2.0, //try different ration based on your preference
      child: Container( //your VideoPlayer
        color: Colors.red,
      ),
    );
  },
),

相关问题