Search code examples
androidflutterdartandroid-cameratextures

The camera displays a stretched image


I have that code:

final size = MediaQuery.of(context).size;
    final deviceRatio = size.width / size.height;
    return Align(
      alignment: Alignment.topCenter,
      child: AspectRatio(
        aspectRatio: deviceRatio,
        child: Stack(
          children: <Widget>[
            CustomPaint(
              foregroundPainter: MeasureFaceOutline(isPosCorrect: true),
              child: Transform(
                alignment: Alignment.center,
                transform: Platform.isIOS ? Matrix4.rotationX(math.pi) : Matrix4.identity(),
                child: Texture(textureId: textureId),
              ),
            ),
          ],
        ),
      ),
    );
  }

And my view from camera is very stretched. How can I set ratio (or transform) for display camera view without stretched?

EDIT: If I use CameraPreview like that:

Transform.scale(
                scale: 1.7,
                child: Center(
                  child: CameraPreview(controller!),
                ),
              )

everything is okay, but I have to use Texture instead CameraPreview


Solution

  • You can use FractionallySizedBox which will scale to your container

    FractionallySizedBox(
      heightFactor: 1.0,
      widthFactor: 1.0,
      child: ...
    )