set orientation flutter code example
Example 1: flutter set orientation
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((value) => runApp(MyApp()));
}
Example 2: flutter lock orientation
@override
void initState(){
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
}
Example 3: lock screen orientation flutter
<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>