'Flutter enable screen rotation even if it is disabled by system

I'm trying to build camera app. I have implemented the basic functionality using official's example https://docs.flutter.dev/cookbook/plugins/picture-using-camera

It works fine, I can take picture both in portrait and landscape mode. The problem is what if the user lock their system's orientation change? In standard camera app, the screen will rotate even if I disable the phone's auto rotation.

I tried using

SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
    DeviceOrientation.landscapeLeft,
    DeviceOrientation.landscapeRight,
]);

But doesn't work since the phone's auto rotation is locked.

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source