From 640fd021d5695e0d27ee07f13fce5e37b1cffa2f Mon Sep 17 00:00:00 2001 From: tanay Date: Sat, 16 Jan 2021 17:22:05 -0500 Subject: [PATCH] Fix video aspect ratio (huge black bars on top and bottom of video elements) --- lib/src/replaced_element.dart | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/src/replaced_element.dart b/lib/src/replaced_element.dart index ba50aa3c3f..43cb53d109 100644 --- a/lib/src/replaced_element.dart +++ b/lib/src/replaced_element.dart @@ -292,20 +292,23 @@ class VideoContentElement extends ReplacedElement { Widget toWidget(RenderContext context) { final double _width = width ?? (height ?? 150) * 2; final double _height = height ?? (width ?? 300) / 2; - return Container( - child: Chewie( - controller: ChewieController( - videoPlayerController: VideoPlayerController.network( - src.first ?? "", + return AspectRatio( + aspectRatio: _width / _height, + child: Container( + child: Chewie( + controller: ChewieController( + videoPlayerController: VideoPlayerController.network( + src.first ?? "", + ), + placeholder: poster != null + ? Image.network(poster) + : Container(color: Colors.black), + autoPlay: autoplay, + looping: loop, + showControls: showControls, + autoInitialize: true, + aspectRatio: _width / _height, ), - placeholder: poster != null - ? Image.network(poster) - : Container(color: Colors.black), - autoPlay: autoplay, - looping: loop, - showControls: showControls, - autoInitialize: true, - aspectRatio: _width / _height, ), ), );