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', {