Reputation: 3927
void main(){
///
/// Force the layout to Portrait mode
///
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
runApp(new MyApp());
}
Upvotes: 11
Views: 9807
Reputation: 1
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(),));
}
Upvotes: -2
Reputation: 10161
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
Upvotes: 12
Reputation: 3265
Here is the code working for both Android
and iOS
Future main() async {
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
runApp(new MyApp());
}
Upvotes: 2