How can I get the current screen orientation?
Activity.getResources().getConfiguration().orientation
Activity.getResources().getConfiguration().orientation
Step #1: Make your AsyncTask a static nested class, or an entirely separate class, just not an inner (non-static nested) class. Step #2: Have the AsyncTask hold onto the Activity via a data member, set via the constructor and a setter. Step #3: When creating the AsyncTask, supply the current Activity to the constructor. Step … Read more
Import package:flutter/services.dart, then Put the SystemChrome.setPreferredOrientations inside the Widget build() method. Example: class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, DeviceOrientation.portraitDown, ]); return new MaterialApp(…); } } Update This solution mightn’t work for some IOS devices as mentioned in the updated flutter documentation on Oct 2019. They Advise to fixed the … Read more
Don’t apply the orientation to the application element, instead you should apply the attribute to the activity element, and you must also set configChanges as noted below. Example: <activity android:screenOrientation=”portrait” android:configChanges=”orientation|keyboardHidden”> </activity> This is applied in the manifest file AndroidManifest.xml.
The current configuration, as used to determine which resources to retrieve, is available from the Resources’ Configuration object: getResources().getConfiguration().orientation; You can check for orientation by looking at its value: int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { // In landscape } else { // In portrait } More information can be found in the … Read more