0

I want to disable the landscape mode. I tried to allow only portrait mode using following code. But it is not working with my physical device. How to solve this?

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

void main() {
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
  runApp(MyApp());
}
PrasadM96
  • 571
  • 2
  • 6
  • 15

1 Answers1

4

You need to paste the code in Widget build(). Consider this answer for more details

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      SystemChrome.setPreferredOrientations([
        DeviceOrientation.portraitUp,
        DeviceOrientation.portraitDown,
      ]);
      return new MaterialApp(...);
    }
  }
Hamza
  • 1,523
  • 15
  • 33