Favourite List
Nothing Added.

Flutter App Orientation Setup Portrait or Landscape Mode

Flutter App Orentation

There are two orientations, i.e Landscape mode and Portrait mode. Flutter uses system default mode or follow the sensor for screen rotation. After reading this article you will be able to set your Flutter app orentation and make it portrait or landscape easily. See the example below and learn how to set Orientation.

Set Portrait Mode of Flutter App

Orentation depends on Flutter Service package. So first of all import the service package.
import 'package:flutter/services.dart';
Now Add this lines of code on main.dart file.

void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
/* DeviceOrientation.portraitup, */
DeviceOrientation.portraitDown,
]).then((value) => runApp(MyApp()));
runApp(MyApp());
}

Set Landscape Mode of Flutter App

Now, chan this values to set your app into Landscape Mode.
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);

Preview

So the codes will be look like that. Now run your app, it will now follow as you set it. 

Orentation Set

Conclusion

In our next tutorial we will demonstrate how to change orentation by click on a button on your Flutter App. If you think this information helps you then please comments and share it with your geeky friend. Thank You
Next Post Previous Post
Feels like
No Comment
Add Comment
comment url