I want to block the landscape mode for some pages in my application and that page should always be in portrait. I Tried some code but that make entire application portrait.
CodePudding user response:
In initState you can set portrait like following.
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
}
Then on dispose method you can set all mode you want like following.
@override
void dispose() {
super.dispose();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}