androidflutterflutter-layout

How to set Flutter CameraPreview Size "Fullscreen"


Iam using CameraPreview for measuring height of an object,But the issue was i cant able to set cameraPreview height full screen..

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.

Mycode:

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),
                ),
              ),);

Kindly help me to fit CameraPreview "FULLSCREEN" without image streching..

enter image description here


Solution

  • Issue has been solved by wrapping Centre widget in Transform widget

    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),
                           ),
                       ),),);