Search code examples
flutterorientation

Flutter: Device specific orientation


In flutter how would I disable landscape orientation in Mobile below 700 pixels width only? For any other device above this they are allowed to use landscape or portrait orientation.

Thanks


Solution

  • class MyApp extends StatelessWidget {
    
      MyApp({Key key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        if (MediaQuery.of(context).size.width < 600) {
          SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
        //Write your code here
        }else{
           //write your other code if needed
        }
        return MaterialApp(
          home: MyHomePage(),
        );
      }
    }