Repository: flutter
Issue: [camera][iOS] Screen freezes while rotating device
Labels: platform-ios,p: camera,package,has reproducible steps,P2,team-ios,triaged-ios,found in release: 3.13

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

With the phone system camera, users do not see rebuilds when they rotate the phone.
However, it seems that rebuilds occur with current version of camera plugin and idk whether this is a bug or not (see videos below).

**If this is not a bug:**
We can invoke  `_cameraController.lockCaptureOrientation()` to avoid rebuilds on device rotation, but then a landscape pic/video will look vertical and we should rotate it before saving to gallery. For pics, that is not a big deal, but for videos it would take much time. We can rotate video without transcoding (only by adding rotation tag inside meta via ffmpeg), but not all players are fine with that and a landscape video might be played as a vertical video.

**If this is a bug:**
Is there a way to decouple 1) `sensor orientation` with 2) `preview widget orientation`?
Coz, inside `camera_preview.dart` we can have 2) looking good after whatever device orientation by just working on `AspectRatio` and `RotatedBox`. So if changes of sensor orientation didn't cause a rebuild on dart side, then that would be a fix.

In a word, if doable, sensor orientation would be used "when taking pic/video" so that they will be be landscape or vertical as expected, and on the dart side we use only "RotatedBox/AspectRatio" to display preview correctly after a device rotation (avoiding rebuild caused by the sensor)




### Expected results

No flickering / rebuild during device rotation

### Actual results

Flickering / rebuild occurs during device rotation

### Code sample

Issue is reproducible with official demo:
https://github.com/flutter/packages/tree/main/packages/camera/camera

```dart
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';

late List<CameraDescription> _cameras;

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  _cameras = await availableCameras();
  runApp(const CameraApp());
}

/// CameraApp is the Main Application.
class CameraApp extends StatefulWidget {
  /// Default Constructor
  const CameraApp({super.key});

  @override
  State<CameraApp> createState() => _CameraAppState();
}

class _CameraAppState extends State<CameraApp> {
  late CameraController controller;

  @override
  void initState() {
    super.initState();
    controller = CameraController(_cameras[0], ResolutionPreset.max);
    controller.initialize().then((_) {
      if (!mounted) {
        return;
      }
      setState(() {});
    }).catchError((Object e) {
      if (e is CameraException) {
        switch (e.code) {
          case 'CameraAccessDenied':
            // Handle access errors here.
            break;
          default:
            // Handle other errors here.
            break;
        }
      }
    });
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    if (!controller.value.isInitialized) {
      return Container();
    }
    return MaterialApp(
      home: CameraPreview(controller),
    );
  }
}
```



### Screenshots or Video

This is videos showcasing the issue. Notice that videos are not related to sample code, but issue occurs with sample code as well.

**Good**
It can be noticed no rebuilds during device rotation but with this setting we would be forced to rotate captured media before saving to gallery.

https://github.com/flutter/flutter/assets/53510751/8c3c9329-2f87-4a99-96d3-bea75a33f6da



**Bad**
It can be noticed a rebuild every time user rotates device. We don't know whether this is a bug caused by either an extra delay due to platform view or a rebuild on dart side that could be avoided somehow.

https://github.com/flutter/flutter/assets/53510751/b83bfd6e-6fb3-4ec0-94d7-4efba03dea03




### Logs

<details><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

[✓] Flutter (Channel master, 3.16.0-15.0.pre.27, on macOS 12.6.5 21G531 darwin-arm64, locale en-IT)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] Connected device (3 available)
[✓] Network resources