skip to Main Content

I need one help form You end, I am implementing one camera project as well, i have to make take picture in Landscape mode only, i don’t want mode, i am not able to view lands cape mode, always in portrait mode only, i cannot change lands cape mode, How to change oreaintaion, Any idea,

This is the i am using controller,

CameraController? controller;
 controller = CameraController(
      cameraDescription,
      ResolutionPreset.high,
      enableAudio: enableAudio,
      androidUseOpenGL: useOpenGL,
      
    );

  //UI
 return RotatedBox(
      quarterTurns: 7,
      //  aspectRatio: controller!.value.previewSize!.aspectRatio,
      child: CameraPreview(controller!),
    );

This is the controller i am using for camera purpose,I cannot change in Landscape mode, how to do, is any have any Idea , Please comment, it would be appreciated

3

Answers


  1. CameraController? controller;

    // Initialize the CameraController with landscape orientation
    controller = CameraController(
    cameraDescription,
    ResolutionPreset.high, // Choose an appropriate resolution preset
    enableAudio: enableAudio,
    androidUseOpenGL: useOpenGL,
    );

    // UI
    return RotatedBox(
    quarterTurns: 1, // Rotate by 90 degrees clockwise for landscape orientation
    child: CameraPreview(controller!),
    );

    Login or Signup to reply.
  2. use quarterTurns property to move camera orientation.

    RotatedBox(
        quarterTurns: 1, // Adjust this value as per your needed
        child: Stack(
          children: [
            Positioned.fill(
              child: AspectRatio(
                aspectRatio: controller.value.aspectRatio,
                child: CameraPreview(controller),
              ),
            ),
          ],
        ),
      ),
    
    Login or Signup to reply.
  3. RotatedBox(
      quarterTurns: 1, // Rotate preview to landscape
      child: CameraPreview(controller!),
    ),
    

    If you need to handle potential orientation changes (e.g., during app backgrounding/foregrounding), consider using the OrientationBuilder widget to adapt UI elements based on the device’s current orientation. However, this might not be strictly necessary if you’ve locked the orientation.

    OrientationBuilder(
      builder: (context, orientation) {
        if (orientation == Orientation.landscape) {
          // Landscape UI
        } else {
          // Handle potential portrait mode (if not locked)
        }
      },
    ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search