Force portrait mode

Flutter tips Published on

Keep Your App in Portrait Mode

Ever found yourself wishing your app just stayed upright? Sometimes, you design an app specifically for portrait view, and having it switch to landscape just doesn't make sense.

Think about it, how often do you really use certain apps sideways? For many, keeping the screen vertical is key.

How to Lock to Portrait

Flutter makes it simple to lock your app's screen orientation. You can tell your app to only allow portrait modes.

The Simple Code

Here's the little piece of magic code you need:

SystemChrome.setPreferredOrientations([
  DeviceOrientation.portraitUp,
  DeviceOrientation.portraitDown,
]);

Where to Put It

You need to run this code right at the start of your app. The best place is inside your main() function, just before you call runApp().

void main() {
  WidgetsFlutterBinding.ensureInitialized(); // Good practice
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);
  runApp(MyApp()); // Your app widget
}
What it Does

By setting the preferred orientations to only portraitUp and portraitDown, you prevent the app from rotating into landscape mode, no matter how the user holds their device.

And just like that, your app stays nicely in portrait mode!

Save 3 months of work

Create your app using our 6 years of making Flutter apps and more than 50+ apps

kickstarter for flutter apps

Frequently Asked Questions

What does 'portrait mode' mean?

Portrait mode is when your phone or tablet screen is taller than it is wide, like holding a book.

Why would I force an app into portrait mode?

Some apps are designed specifically for a vertical layout, and forcing portrait mode ensures the user experience is always as intended, preventing awkward layouts or broken elements in landscape.

Can I force the app into landscape mode instead?

Yes, you can specify landscape orientations (`DeviceOrientation.landscapeLeft`, `DeviceOrientation.landscapeRight`) in the same list instead of or in addition to the portrait ones.

Where exactly does this code go?

Place the `SystemChrome.setPreferredOrientations` call within your `main()` function, usually before the `runApp()` call.

Read more
You may also be interested in
Get ⭐ reviews on stores  blog card image
Get ⭐ reviews on stores
Published on 2025-05-19T07:11:44.058Z
Dumb and smarter  blog card image
Dumb and smarter
Published on 2025-05-19T07:11:02.519Z
ApparenceKit is a flutter template generator tool by Apparence.io © 2025.
All rights reserved