Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 142 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flutter: how to prevent device orientation changes and force portrait?

#21
**Flutter orientation lock: portrait only**

In Flutter we have SystemChrome.setPreferredOrientation() ([see documentation][1]) to define preferred orientation. Exactly this method you can find in all those articles about setup orientation in Flutter. Let’s see how we can use it:


import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
// We need to call it manually,
// because we going to call setPreferredOrientations()
// before the runApp() call
WidgetsFlutterBinding.ensureInitialized();

// Than we setup preferred orientations,
// and only after it finished we run our app
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((value) => runApp(MyApp()));
}

**iOS**

Open project in Xcode `(ios/Runner.xcworkspace)`, choose `Runner` in the project navigator, select Target `Runner` and on Tab `General` in section D`eployment Info` we can setup Device Orientation:

[![enter image description here][2]][2]

Also, we can do it manually without opening Xcode at all — just edit `ios/Runner/Info.plist`. Open it as a text file, find key `UISupportedInterfaceOrientation` and leave only desired values:

<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>


**Android**

To define orientation for `Android` we need to edit `ApplicationManifest`. Open `android/app/src/main/AndroidManifest.xml` and add an attribute screenOrientation for a `main` activity:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.orientation_lock_example">
<application ...>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
...
/>
...
</activity>
...
</application>
</manifest>

And that’s all. [Here][3] is the repository with an example app:

Hope this was helpful.


[1]:

[To see links please register here]

[2]:

[3]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through