Disable Screen Rotation Orientation Using Flutter App

admin_img Posted By Bajarangi soft , Posted On 10-10-2020

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.

Disable Screen Rotation Orientation Using Flutter App

Disable Screen Rotation Orientation
Complete Code For Disable Screen Rotation Orientation In Flutter
Main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart' ;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
    ]);
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        backgroundColor: Colors.black,
          appBar: AppBar(
            title: Text("Disable Screen Rotation in Flutter App"),
          ),
          body: SafeArea(
              child : Center(
                  child:Text('Disable Screen Rotation in Flutter App',
                    style: TextStyle(fontSize:  20,color: Colors.white),)
              )
          )
      ),
    );
  }
}

Related Post