Skip to main content

Flutter Set Default App Orientation Landscape Mode

In every Mobile and Tablet device there are two types of orientation Landscape and Portrait. By enabling these 2 orientation we can rotate our app 360 degree in mobile device. Landscape orientation has 2 sub parts Landscape left and landscape right. Same the Portrait mode has 2 sub parts Portrait Up and Portrait Down. We can set any of these orientation in our flutter app with SystemChrome.setPreferredOrientations([]) method. It supports orientation array.

Flutter Set Default App Orientation Landscape Mode

1. First of all we have to import services.dart and material.dart file in our flutter project.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2. Creating void main() function for app and Here we have to set our preferred orientation landscape right and landscape left.
void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
  runApp(App());
}
3. Creating our App class.
class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
        home: Scaffold(
            body: Center(
      child: Text(
        'Flutter Set Default App Orientation Landscape Mode',
        style: TextStyle(fontSize: 24),
        textAlign: TextAlign.center,
      ),
    )));
  }
}
Screenshot:
Flutter Set Default App Orientation Landscape Mode
Source code for main.dart file:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
  runApp(App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
        home: Scaffold(
            body: Center(
      child: Text(
        'Flutter Set Default App Orientation Landscape Mode',
        style: TextStyle(fontSize: 24),
        textAlign: TextAlign.center,
      ),
    )));
  }
}

Comments