DISCOVER FLUTTER — WEEK #22

Change Screen Orientation In Flutter

Photo by eberhard grossgasteiger on Unsplash

Setting Screen Orientation

import 'package:flutter/services.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized(); SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]).then((_){
runApp(MyApp());
});
}

Setting to Portrait Mode Only

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

Setting to Landscape Mode Only

SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight])

Getting device orientation

MediaQuery.of(context).orientation

Conclusion

On my journey to become a Flutter dev I will be sharing knowledge by writing short texts about what new know-how’s I’ve learned, in the next 30 weeks.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store