How to Lock Screen Orientation in Flutter
Many developers who want to lock screen orientation in Flutter go straight to AndroidManifest.xml and add android:screenOrientation="portrait". That works, but there’s a better way. The Dart approach: SystemChrome Add the import and configure the orientations at the beginning of main(), before calling runApp: import 'package:flutter/services.dart'; // ← required import void main() { WidgetsFlutterBinding.ensureInitialized(); // needed before any system call SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, DeviceOrientation.portraitDown, ]); runApp(const MyApp()); } WidgetsFlutterBinding.ensureInitialized() is required to make sure Flutter is ready before any system call. Without it, setPreferredOrientations may not work correctly. ...