<?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>Orientação on thomazrb</title><link>https://thomazrb.github.io/pt-br/tags/orienta%C3%A7%C3%A3o/</link><description>Recent content in Orientação on thomazrb</description><generator>Hugo -- 0.147.9</generator><language>pt-br</language><lastBuildDate>Wed, 17 Jun 2026 13:30:00 -0300</lastBuildDate><atom:link href="https://thomazrb.github.io/pt-br/tags/orienta%C3%A7%C3%A3o/index.xml" rel="self" type="application/rss+xml"/><item><title>Como Travar a Orientação de Tela no Flutter</title><link>https://thomazrb.github.io/pt-br/posts/flutter-screen-orientation/</link><pubDate>Wed, 17 Jun 2026 13:30:00 -0300</pubDate><guid>https://thomazrb.github.io/pt-br/posts/flutter-screen-orientation/</guid><description>&lt;p>Muita gente que quer travar a orientação de um app Flutter vai direto no &lt;code>AndroidManifest.xml&lt;/code> e adiciona &lt;code>android:screenOrientation=&amp;quot;portrait&amp;quot;&lt;/code>. Funciona, mas existe uma forma melhor.&lt;/p>
&lt;h3 id="a-abordagem-dart-systemchrome">A abordagem Dart: &lt;code>SystemChrome&lt;/code>&lt;/h3>
&lt;p>Adicione o import e configure as orientações logo no início da função &lt;code>main()&lt;/code>, antes de chamar &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">// ← import necessário
&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">// precisa disso antes de mexer no sistema
&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>O &lt;code>WidgetsFlutterBinding.ensureInitialized()&lt;/code> é necessário para garantir que o Flutter esteja pronto antes de qualquer chamada de sistema. Sem ele, o &lt;code>setPreferredOrientations&lt;/code> pode não funcionar corretamente.&lt;/p></description></item></channel></rss>