How to set Flutter CameraPreview Size "Fullscreen"
Problem is same with this link however the solution isn't working on my phone (LG G5). Leaving a black margin around the camera preview for back camera however works fine for front camera but this time recorded video will cover a larger area than the preview video. I tried on other phones front and back camera preview works just fine but the actual recorded video covering more area problem still persists.
Edit: Problem originates from the Camera package itself not the framework for anyone out there who has a similar problem.
Further investigation and playing around with the package revealed that aspect ratio value that is returned from the package is not guaranteed to match the device's aspect ratio however works fine most of the cases.
final size = MediaQuery.of(context).size;
final deviceRatio = size.width / size.height;
return Scaffold(
key: _scaffoldKey,
body: Stack(
children: <Widget>[
controller != null
? Center(
child: Transform.scale(
scale: controller.value.aspectRatio / deviceRatio,
child: new AspectRatio(
aspectRatio: controller.value.aspectRatio,
child: new CameraPreview(controller),
),
),
)
: Container(),
void onNewCameraSelected(CameraDescription cameraDescription) async {
if (controller != null) {
await controller.dispose();
}
controller = CameraController(
cameraDescription,
ResolutionPreset.high,
enableAudio: enableAudio,
);
// If the controller is updated then update the UI.
controller.addListener(() {
if (mounted) setState(() {});
if (controller.value.hasError) {
showInSnackBar('Camera error ${controller.value.errorDescription}');
}
});
try {
await controller.initialize();
} on CameraException catch (e) {
_showCameraException(e);
}
if (mounted) {
setState(() {
print("controller inited");
});
}
}