void main(){
///
/// Force the layout to Portrait mode
///
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
runApp(new MyApp());
}
Asked
Active
Viewed 9,495 times
11

Raj008
- 3,539
- 2
- 28
- 26
-
Please find this updated answer https://stackoverflow.com/a/50884081/348589 – Shady Mohamed Sherif Jan 04 '20 at 16:40
3 Answers
12
Put this code in the MyApp() and don't forget to import the services package:
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
Like below:
import 'package:flutter/services.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
return new MaterialApp();
}
}
Update
There is a bug which prevents this code working on ipads github.com/flutter/flutter/issues/27235 as per comment by @F-1.
Below comment may help you out.
https://github.com/flutter/flutter/issues/27235#issuecomment-508995063

ibhavikmakwana
- 8,948
- 4
- 20
- 39
-
I just edited this but it doesn't seem to work anyway...at least not in iOS. – Hasen Jul 10 '19 at 08:06
-
-
There is a bug which prevents this code working on ipads https://github.com/flutter/flutter/issues/27235 – F-1 Jul 11 '19 at 08:33
2
Here is the code working for both Android
and iOS
Future main() async {
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
runApp(new MyApp());
}

Sunny
- 3,134
- 1
- 17
- 31
-
At time of writing this won't work on iPads https://github.com/flutter/flutter/issues/27235 – F-1 Jul 11 '19 at 08:33
-2
Following code worked for me.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app/splashScreen.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
runApp(MaterialApp(home: splashScreen(),));
}