Deep dive into screen orientation in Flutter

<p>The mobile application usually develops to support both portrait and landscape mode without any issue. But in some special case, you may need to set the orientation of the application to fix direction to get proper real state space to each component</p> <p><iframe frameborder="0" height="435" scrolling="no" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FKyB4LZTCrXE8W9HqiA%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fstickers%2Fgenies-transparent-geeryanimation-KyB4LZTCrXE8W9HqiA&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2FKyB4LZTCrXE8W9HqiA%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" title="Gravity Geeryanimation Sticker by Genies for iOS &amp; Android | GIPHY" width="435"></iframe></p> <h1>Set the orientation in flutter</h1> <p>First, you have to import the services package.</p> <pre> import &#39;package:flutter/services.dart&#39;;</pre> <p>Next, you can set orientation by setting the value to setPreferredOrientations method in SystemChrome class. In the Flutter the application entry point is the main method. So you can set orientation before call the runApp method in the main method. But if you need to call a binding before the runApp method, you must call the&nbsp;<a href="https://api.flutter.dev/flutter/widgets/WidgetsFlutterBinding/ensureInitialized.html" rel="noopener ugc nofollow" target="_blank">ensureInitialized</a>&nbsp;method in WidgetsFlutterBinding class.</p> <p><a href="https://suryadevsingh24032000.medium.com/deep-dive-into-screen-orientation-in-flutter-bc81858f2c57"><strong>Read More</strong></a></p>