<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>SystemChrome on thomazrb</title><link>https://thomazrb.github.io/tags/systemchrome/</link><description>Recent content in SystemChrome on thomazrb</description><generator>Hugo -- 0.147.9</generator><language>en</language><lastBuildDate>Wed, 17 Jun 2026 13:30:00 -0300</lastBuildDate><atom:link href="https://thomazrb.github.io/tags/systemchrome/index.xml" rel="self" type="application/rss+xml"/><item><title>How to Lock Screen Orientation in Flutter</title><link>https://thomazrb.github.io/posts/flutter-screen-orientation/</link><pubDate>Wed, 17 Jun 2026 13:30:00 -0300</pubDate><guid>https://thomazrb.github.io/posts/flutter-screen-orientation/</guid><description>&lt;p>Many developers who want to lock screen orientation in Flutter go straight to &lt;code>AndroidManifest.xml&lt;/code> and add &lt;code>android:screenOrientation=&amp;quot;portrait&amp;quot;&lt;/code>. That works, but there&amp;rsquo;s a better way.&lt;/p>
&lt;h3 id="the-dart-approach-systemchrome">The Dart approach: &lt;code>SystemChrome&lt;/code>&lt;/h3>
&lt;p>Add the import and configure the orientations at the beginning of &lt;code>main()&lt;/code>, before calling &lt;code>runApp&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">import&lt;/span> &lt;span style="color:#e6db74">&amp;#39;package:flutter/services.dart&amp;#39;&lt;/span>; &lt;span style="color:#75715e">// ← required import
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">void&lt;/span> main() {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> WidgetsFlutterBinding.ensureInitialized(); &lt;span style="color:#75715e">// needed before any system call
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> SystemChrome.setPreferredOrientations([
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> DeviceOrientation.portraitUp,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> DeviceOrientation.portraitDown,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ]);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> runApp(&lt;span style="color:#66d9ef">const&lt;/span> MyApp());
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>WidgetsFlutterBinding.ensureInitialized()&lt;/code> is required to make sure Flutter is ready before any system call. Without it, &lt;code>setPreferredOrientations&lt;/code> may not work correctly.&lt;/p></description></item></channel></rss>