如何将Flutter CameraPreview大小设置为“全屏" [英] How to set Flutter CameraPreview Size "Fullscreen"
本文介绍了如何将Flutter CameraPreview大小设置为“全屏"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用CameraPreview来测量对象的高度,但是问题是我无法全屏设置cameraPreview高度.
Iam using CameraPreview for measuring height of an object,But the issue was i cant able to set cameraPreview height full screen..
我尝试过定位的小部件,它会填满整个屏幕,但图像会被拉伸. 我已经尝试过 Transform Widget ,但是高度无法填充全屏,即将出现空白.图像没有拉伸.
I have tried Positioned widget, it fills the screen but the image was stretched. I have tried Transform Widget, but height does not fills fullscreen, white space is coming.Image is not stretched.
我的代码:
final size = MediaQuery.of(context).size;
final deviceRatio = size.width / size.height;
return Stack(
children: <Widget>[
Transform.scale(
scale: controller.value.aspectRatio/deviceRatio,
child: new AspectRatio(
aspectRatio: controller.value.aspectRatio,
child: new CameraPreview(controller),
),
),);
请帮助我适应CameraPreview"FULLSCREEN",而不会产生图像拉长的情况.
推荐答案
问题已通过将中心"窗口小部件包装在转换"窗口小部件中解决
final size = MediaQuery.of(context).size;
final deviceRatio = size.width / size.height;
return Stack(
children: <Widget>[
Center(
child:Transform.scale(
scale: controller.value.aspectRatio/deviceRatio,
child: new AspectRatio(
aspectRatio: controller.value.aspectRatio,
child: new CameraPreview(controller),
),
),),);
这篇关于如何将Flutter CameraPreview大小设置为“全屏"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文