From 5e0f0b59d8dc3da8a8654433d45f3d321b1d5e0e Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Mon, 2 Jun 2025 19:26:13 +0200 Subject: [PATCH] prevent display orientation flip when device rotation is locked --- CHANGELOG.md | 1 + lib/services/window_service.dart | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21f0e9b0c..6c95f5d38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### Changed - downgraded Flutter to stable v3.27.4 +- prevent display orientation flip when device rotation is locked ### Fixed diff --git a/lib/services/window_service.dart b/lib/services/window_service.dart index f0a9b8087..341f5ad07 100644 --- a/lib/services/window_service.dart +++ b/lib/services/window_service.dart @@ -74,20 +74,24 @@ class PlatformWindowService implements WindowService { return false; } + // cf https://developer.android.com/guide/topics/manifest/activity-element#screen + // cf Android `ActivityInfo.ScreenOrientation` + static const screenOrientationUnspecified = -1; // SCREEN_ORIENTATION_UNSPECIFIED + // use the `USER` variants rather than the `SENSOR` ones, + // so that it does not flip even if it is reversed by sensor + static const screenOrientationUserLandscape = 11; // SCREEN_ORIENTATION_USER_LANDSCAPE + static const screenOrientationUserPortrait = 12; // SCREEN_ORIENTATION_USER_PORTRAIT + @override Future requestOrientation([Orientation? orientation]) async { - // cf Android `ActivityInfo.ScreenOrientation` late final int orientationCode; switch (orientation) { case Orientation.landscape: - // SCREEN_ORIENTATION_SENSOR_LANDSCAPE - orientationCode = 6; + orientationCode = screenOrientationUserLandscape; case Orientation.portrait: - // SCREEN_ORIENTATION_SENSOR_PORTRAIT - orientationCode = 7; + orientationCode = screenOrientationUserPortrait; default: - // SCREEN_ORIENTATION_UNSPECIFIED - orientationCode = -1; + orientationCode = screenOrientationUnspecified; } try { await _platform.invokeMethod('requestOrientation', {