Record square video - Flutter - flutter

I have this scenario:
i have an app that records video and this video must be square, for this reason in build method I setup camera preview in this way:
var size = MediaQuery.of(context).size.width;
return Container(
width: size,
height: size,
child: ClipRect(
child: OverflowBox(
alignment: Alignment.center,
child: FittedBox(
fit: BoxFit.cover,
child: Container(
width: size / _controller.value.previewSize.width,
height:
size / _controller.value.previewSize.height,
child: CameraPreview(this._controller), // this is my CameraPreview
),
),
),
),
);
In this way video is square but only in visualization, when I export it it is rectangular.
There is a way to set the aspect ratio of the camera in order to have a square video output?

Related

How to make a square video 1:1 without losing its aspect ration in Flutter with video_player package

Trying to crop the video of a video to display a preview as a square without changing its width and height.
This is how it makes a square video
Container(
width: 200, //Crop width
height: 200, //Crop height
child: FittedBox(
// alignment: Alignment.center, //Move around the crop
fit: BoxFit.cover,
clipBehavior: Clip.hardEdge,
child: SizedBox(
width: videoController.value.size.width,
height: videoController.value.size.height,
child: AspectRatio(
aspectRatio: videoController.value.aspectRatio,
child: VideoPlayer(
videoController,
),
),
),
),
);

How can I overlay the CustomPaint canvas directly overtop of a video player widget?

This is what I have right now
return AspectRatio(
aspectRatio: MediaQuery.of(context).size.width / MediaQuery.of(context).size.height,
// Use the VideoPlayer widget to display the video.
child: Container(
alignment: Alignment.center,
child: CustomPaint(
foregroundPainter: MyPaint(),
child: VideoPlayer(_controller),
),
),
);
https://flutter.dev/docs/cookbook/plugins/play-video
I need the CustomPaint canvas to be fixed over the top of the video widget, so it stays in the same place regardless of the window size.
How do you implement?
Stack(
children: <Widget>[
Positioned(
left: 0, // can be 100, 200 any number you want
top: 0,
child: [Your view]
),
],
)

Flutter displaying cropped widgets

I would like to paint widgets outside the canvas and display only cropped portion ie., the screen's size or my own size and I want to do this dynamically.
Eg:sample img
I was able to do this by using
UnconstrainedBox(
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
color: Colors.lightBlue,
//width: MediaQuery.of(context).size.width,
//height: MediaQuery.of(context).size.height ,
width: _size.width,
height: _size.height,
child: FittedBox(
alignment: Alignment.bottomCenter,
fit: BoxFit.none,
child: Container(
width: _size.width,
height: _size.height * 2,
child: MyWidget,
),
),
),
),
)
But using this setup allows me only to scale the widget to 3x since the alignment coordinates have only 3 positions along one axis. I want to be able to scale the widget to nx and display any of the portion. Pls help.
Found the solution, used Alignment(x,y) to scale and position the widget ;)

How can I improve image display quality?

Original image
Screenshot
When I try to load an image in my application, it feels like it is somehow not stretching properly.
I tried all the options for the "fit" parameter
And nothing happened
It's my code
SingleChildScrollView(
child: Container(
width: width,
child: Image.network(
'https://img4.manga-chan.me/manga/-9new/t/1568958338_the-gamer-tom-4-glava-290/001.png',
filterQuality: FilterQuality.high,
fit: BoxFit.cover,
),
),
)
What should I do to make the image of original quality?
Did it and it helped me
Wrapped scroll in container
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
Container(
width: width,
height: height,
child: SingleChildScrollView(
child: Image.network(
'https://img4.manga-chan.me/manga/-9new/t/1571807955_the-gamer-tom-4-glava-296/002.png',
filterQuality: FilterQuality.high,
fit: BoxFit.fitWidth,
),
),
)

Flutter - Image taking the whole screen width

In a Detail page, I'd like an image to take the whole width available, on the very top. This is my code:
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Container(
child: Column(
children: <Widget>[
Container(
width: double.infinity,
child: Image.asset(
this.imageLink,
),
)
],
),
),
),
);
The problème is : with the emulator, the result is exactly what I want :
But when I launch the app on a real phone (Galaxy S8 Plus) there are some paddings (top, left and right) and the image doesn't fit the screen width.
Which means that something is not correct in the way I tried to do it with the code.
Where could be the problem ?
I think the reason being original width of image is equal or more than the width of emulator and which is less than your Samsung S8+ width, you need to use
Image.asset(
this.linkImage,
width: double.infinity,
fit: BoxFit.cover,
),
You will have use expanded widget for that or you can use
height: double.infinity,
width: double.infinity,
or
new Image.asset('assets/images/umbrella.png',
width: size.width,
height: size.height,
fit: BoxFit.fill,
)
you can use
fit: BoxFit.cover,