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/bottom or the left/right of the video.
I had hoped the following might achieve this, but I think I must be using FittedBox
incorrectly as it causes my VideoPlayer
to disappear:
final Size size = controller.value.size;
return new FittedBox(
fit: BoxFit.cover,
child: new AspectRatio(
aspectRatio: size.width / size.height,
child: new VideoPlayer(controller)
),
);
Can anyone help me solve this? 🙏
Here's how you do it:Step 1: Wrap the Stack's child widget inside the Position widget. Step 2: Inside the Position widget, add the top , right , bottom , left property and give it a value. For example, setting top:15 and right:0 will position a widget on the top right of your screen with 15 px space from the top.
Draw circle in canvas using canvas. Call endRecording() on the PictureRecorder to get a Picture. Call toImage() on the Picture. Convert image toByteData() . Save image locally using getApplicationDocumentsDirectory() ,only if you want to save.
Finally solved it. There were a few missing pieces:
OverflowBox
with no restrictions so that my child could grow as large as needed.FittedBox
to actually enforce a size to stop the layout system from crashing.ClipRect
in there to stop this from happening.final Size size = controller.value.size;
return new ClipRect(
child: new OverflowBox(
maxWidth: double.infinity,
maxHeight: double.infinity,
alignment: Alignment.center,
child: new FittedBox(
fit: BoxFit.cover,
alignment: Alignment.center,
child: new Container(
width: size.width,
height: size.height,
child: new VideoPlayer(controller)
)
)
)
);
Starting with the above solution I came up with this:
final Size size = _controller.value.size;
return Container(
color: Colors.lightBlue,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.width,
child: FittedBox(
alignment: Alignment.center,
fit: BoxFit.fitWidth,
child: Container(
width: size.width,
height: size.height,
child: VideoPlayer(_controller))),
),
)
The inner Container
provides the size for the Texture
inside the VideoPlayer
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With