Camera Orientation Doesn't Follow the Device Orientation when the Screen Rotation is Turned Off - unity3d

As per the title, I have an AR game embedded in the flutter app that I want to run in landscape mode.
I tried using this code:
#override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
And it did work to set the screen orientation to landscape, but the problem is when the screen rotation is turned off in my phone settings, the background in AR mode starts showing the upside-down view from the camera, which looks a bit weird from the user experience perspective.
Does anybody know how to fix this?

Related

Flutter camera plugin: how do I lockCaptureOrientation on either landscapeRight or landscapeLeft?

I am writing a landscape flutter application that uses the camera plugin.
To make my app landscape, I have the following lines in my main:
WidgetsFlutterBinding.ensureInitialized();
await SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight, DeviceOrientation.landscapeLeft]);
This does not prevent from receiving a landscape image from the camera stream so, after initializing the camera controller, I have the line
_controller?.lockCaptureOrientation(DeviceOrientation.landscapeRight);
With this line, the camera gives only landscape images, but now the app will not work properly in landscapeLeft. Is there a way to enforce the capture orientation to be either landscapeRight
or landscapeLeft?
Try to specify lockCaptureOrientation() after inialization and restart the camera screen.
await cameraController?.initialize();
await cameraController?.lockCaptureOrientation();

Prevent specific widget's rotation in Flutter

Is it possible to prevent a specific widget from rotating?
I'm making an app that switches a portrait screen mode to a landscape screen mode when I turn my device.
But The QR scanner package I use has an issue with the rotation. So, I would like to prevent only the QR scanner widget from rotating. Is it possible in flutter? hopefully, without external package

Device orientation in flutter

How to develop app for both device orientation(portrait and landscape) in flutter. When I rotate my device in landscape, app size will adjust on landscape. If I rotate my device in portrait, app size will adjust on portrait.
The answer is simple called as "responsive design", please have a look to one of the best post about the same subject ;
https://medium.com/flutter-community/developing-for-multiple-screen-sizes-and-orientations-in-flutter-fragments-in-flutter-a4c51b849434
and also from the original source from Flutter documentation ;
https://flutter.dev/docs/development/ui/layout/responsive
Hope this works
you can develop two widgets for each orientation each one has different sizes of text, padding.... using MediaQuery.of(context).orientation to get the current orientation or you can use Layout Builder.
Otherwise, you can lock your app to a specific orientation:
import 'package:flutter/services.dart';
main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
runApp(MyHomePage());
}

How do I switch to landscape orientation

I am using the Agora Flutter Quickstart project. By default the orientation is portrait but I want to switch to landscape. Therefor I have to implement these lines:
VideoEncoderConfiguration videoEncoderConfiguration = new
VideoEncoderConfiguration();
videoEncoderConfiguration.orientationMode =
VideoOutputOrientationMode.FixedLandscape;
AgoraRtcEngine.setVideoEncoderConfiguration(videoEncoderConfiguration);
I don't know where to place these lines. I've tried a lot but the the orientation is still portrait
Import hte following package package:flutter/services.dart
Then add the code below into your build Method of the main App widget
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
This will allow only landscape mode for your app.

Unity app with different screen orientations

I'm developing a game that runs on both mobile phones and tablets.
Currently I'm using only the Portrait orientation for all devices but the portrait orientation looks better on phones meanwhile landscape orientation looks better on tablets.
I set "Portrait" option in the Unity's Player Settings > Resolution and Presentation > Default Orientation but I would like to provide a landscape layout for tablets (without affecting phones).
How I can I do that? Is there any why to programmatically set the Screen orientation when the application starts?
You can try Screen.Orientation
In the Start (or Awake) method of a MonoBehaviour that is added to the stage call:
Screen.Orientation = ScreenOrientation.LandscapeRight
Now you just need to check if the device is tablet or phone, I don't know any way out of the box to do this, but you can check the aspect ratio and base your decision on this.
You can check the aspect ratio by getting Screen.width and Screen.height.