Disable Screen Rotation Orientation in Flutter Enable Portrait Mode Only

There are two device screen orientation present in every mobile or Tablet device Landscape and Portrait. In mobile devices the default screen orientation mode is portrait. Every mobile phone has a Auto Rotation button present on Scrollable Menu bar. By default the Auto Rotation is disabled in mobile phones but we can enable them via Menu bar and the complete mobile phone screen will rotate on device rotation. But sometimes app developer wants to prevent Landscape mode and active only Portrait mode in flutter application. Here comes the DeviceOrientation.portraitUp method of SystemChrome package. This method would enable only the Portrait mode in flutter app. So in this tutorial we would Disable Screen Rotation Orientation in Flutter Android iOS App and Enable Portrait Mode Only.

Contents n this project Disable Screen Rotation Orientation in Flutter Android iOS App and Enable Portrait Mode Only:

1. Import material.dart and services.dart package in your flutter project’s main.dart file.

2. Create void main runApp() method and call our main MyApp class here.

3. Create our main class named as MyApp extends with State less widget.

4. Create SystemChrome.setPreferredOrientations() method to disable Screen rotation in Widget build area of MyApp class just before the return part.

5. Create 1 Text widget in Widget build area to show some text.

6. Complete source code for main.dart file:

Screenshots:

Disable Screen Rotation Orientation in Flutter Portrait Mode Only

4 Comments

  1. Gracias por el post

  2. it work in pwa?

  3. void main() {
    WidgetsFlutterBinding.ensureInitialized();
    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
    .then((_) {
    runApp(new MyApp());
    });

Leave a Reply

Your email address will not be published. Required fields are marked *