admin管理员组

文章数量:1125947

I'm using the CamerAwesome plugin in Flutter to capture images. My goal is to have a 1:1 aspect ratio for both the preview and the final captured image.

While I have set up the preview to display in 1:1, the final captured image seems slightly misaligned—it is translated downward. This makes the preview and the resulting image inconsistent.

How can I ensure that the preview and the final capture are perfectly aligned and maintain the same framing in 1:1 aspect ratio?

Any guidance or examples would be greatly appreciated. Thank you!

class CameraScreen extends StatelessWidget {
  const CameraScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => CameraProvider(),
      child: Scaffold(
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const CameraPreviewWidget(),
            SizedBox(height: 100.w),
            const CameraControlButtons(),
          ],
        ),
      ),
    );
  }
}

class CameraPreviewWidget extends StatelessWidget {
  const CameraPreviewWidget({super.key});

  @override
  Widget build(BuildContext context) {
    final previewSize = 360.w;

    return Center(
      child: SizedBox(
        width: previewSize,
        height: previewSize,
        child: Consumer<CameraProvider>(
          builder: (context, cameraProvider, child) {
            return CameraAwesomeBuilder.custom(
              saveConfig: SaveConfig.photo(),
              sensorConfig: SensorConfig.single(
                sensor: Sensor.position(SensorPosition.back),
                aspectRatio: CameraAspectRatios.ratio_1_1,
                flashMode: cameraProvider.flashMode,
                zoom: 0.0,
              ),
              builder: (cameraState, previewSize) {
                return cameraState.when(
                  onPreparingCamera: (state) =>
                      const Center(child: CircularProgressIndicator()),
                  onPhotoMode: (state) {
                    cameraProvider.setCameraState(state);
                    return SizedBox(
                      width: 360.w,
                      height: 360.w,
                    );
                  },
                );
              },
            );
          },
        ),
      ),
    );
  }
}```
[![camera][1]][1]


  [1]: .png

本文标签: flutterHow to align preview and captured image in 11 using CamerAwesomeStack Overflow