mitesh77 / Best-Flutter-UI-Templates

completely free for everyone. Its build-in Flutter Dart.
Other
20k stars 4.48k forks source link

Device Orientation does not work properly #78

Closed mrietunjoy closed 1 year ago

mrietunjoy commented 3 years ago

Hi, while you are setting the device orientation, the orientation is set as per only the first item in the array which is sent as a argument of setPreferredOrientations in main.dart. Line 10.

await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]).then((_) => runApp(MyApp()));

I tried running it in a virtual device as well as a Mobile device. But if the first item is changed only then it comes to effect.

landscape Right This occured when I set the first item in the list to DeviceOrientation.landscapeLeft

Desktop (please complete the following information):

Smartphone (please complete the following information):

Thanks

mrietunjoy commented 3 years ago

So, currently I think it is respected in iPad. I have shared a link below which shows the limitation, of this approach.

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

mrietunjoy commented 2 years ago

And if anyone is checking for this issue. The above code will work for one particular Orientation like PortraitUp or PortraitDown which ever is placed in the array first.

But if you want to assign a Orientation then there is no need for the above code. For more details on DeviceOrientation you can check, the docs: https://api.flutter.dev/flutter/services/DeviceOrientation-class.html