Ashish
Ashish

Reputation: 6919

Allow user to Landscape Right and Left without using Auto Rotation

I tried using the SystemChrome to change the orientation and it works for Lock ScreenOrientation. But As i provided two orientation. Application takes the first orientation until user start the Auto Orientation from Setting.

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

Is it possible to allow user to change the orientation without using Auto-Orientation Service ?

Upvotes: 0

Views: 811

Answers (3)

Aamil Silawat
Aamil Silawat

Reputation: 8239

Hey @Ashish I found one link for you for Orientation functionality and Concept

SystemChrome.setPreferredOrientation

Upvotes: 0

Q.u.a.n.g L.
Q.u.a.n.g L.

Reputation: 1614

The idea here is using make a sensor plugin to take only the screen orientation landscape info. Sensor will work even user locks the orientation.

https://www.techrepublic.com/article/pro-tip-use-android-sensors-to-detect-orientation-changes/

From the flutter site, put a listener somewhere and take a rotation programmatically by setPreferredOrientations method.

https://master-api.flutter.dev/flutter/services/SystemChrome/setPreferredOrientations.html

Upvotes: 0

Spatz
Spatz

Reputation: 20158

It works only with android devices: add attribute to main activity in AndroidManifest.xml

<activity
    android:screenOrientation="sensorLandscape"
    ...

and now screen retains landscape orientation, but can be either normal or reverse landscape based on the device sensor. The sensor is used even if the user has locked sensor-based rotation.

Upvotes: 1

Related Questions