I'm developing responsive flutter web application. I want my application to be suggested only in portrait orientation, since I did not consider the landscape mode for the application. Is there any way to lock screen orientation for the flutter web application?
Asked
Active
Viewed 1,261 times
1
-
Check the following thread, it discusses your exact wish. https://stackoverflow.com/questions/49418332/flutter-how-to-prevent-device-orientation-changes-and-force-portrait – Tim Jacobs Sep 07 '21 at 09:59
-
I already tried that but didn't work for me. It keeps changing its orientation when I click rotate button. – Whao Liang Sep 07 '21 at 10:11
-
is it web application? That can be opened only from browser? – Hamdam Muqimov Sep 07 '21 at 10:43
-
It is web application. I build it by `flutter run -d chrome --web-renderer html`. – Whao Liang Sep 07 '21 at 11:05
1 Answers
0
You can use MediaQuery.of(context).orientation
with RotatedBox
to artificially lock it.
By that I mean to use orientation switch in build method and conditionally rotate content to always have correct aspect ratio. You use RotatedBox
on highest level to rotate the whole thing
Widget build(BuildContext context) {
return RotatedBox(...)
}

Krzysztof Nowicki
- 98
- 8
-
In your index.xml file, change window.flutterWebRenderer = "html"; to window.flutterWebRenderer = "canvaskit"; – Gabriel Almeida Dec 02 '22 at 07:03