0

i am trying to set landscape orientation for the tablet after running my app, always running in portrait mode, here is what I did:

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  // Set landscape orientation
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.landscapeLeft,
    DeviceOrientation.landscapeRight,
  ]);
  runApp(MyApp());
}
Ayoub Boumzebra
  • 3,885
  • 3
  • 21
  • 37

3 Answers3

1

Apparently, the orientation is not working on Nexus 9 API R emulator tablet, but it works fine on Pixel C API R emulator and Nexus 7 2012 API R tablet

Ayoub Boumzebra
  • 3,885
  • 3
  • 21
  • 37
0

Add This Type before materialApp

  Widget build(BuildContext context) {
        SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight]);
        return MaterialApp();
Masum Billah Sanjid
  • 1,029
  • 1
  • 7
  • 19
0

There are two situations,

  1. Set the orientation for the entire app and never let the user change the orientation.- you have to set android:screenOrientation="landscape" in the FlutterActivity in the AndroidManifest.xml file.

  2. Set the orientation to the landscape at first and change as the user wants.-

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

will go into the Main AppState Management class.

Sushanth
  • 1,373
  • 1
  • 10
  • 15