diff --git a/lib/screens/video_player_screen.dart b/lib/screens/video_player_screen.dart index be5fb4c3..0f8a57fb 100644 --- a/lib/screens/video_player_screen.dart +++ b/lib/screens/video_player_screen.dart @@ -998,6 +998,7 @@ class VideoPlayerScreenState extends State with WidgetsBindin if (navigator.canPop()) { _isExiting.value = true; await _sendStoppedProgressOnce(); + await _restoreSystemUiAndOrientation(); if (!mounted) return; navigator.pop(true); } @@ -1012,6 +1013,7 @@ class VideoPlayerScreenState extends State with WidgetsBindin if (navigator.canPop()) { _isExiting.value = true; await _sendStoppedProgressOnce(); + await _restoreSystemUiAndOrientation(); if (!mounted) return; navigator.pop(true); } @@ -1020,6 +1022,29 @@ class VideoPlayerScreenState extends State with WidgetsBindin } } + Future _restoreSystemUiAndOrientation() async { + try { + await OrientationHelper.restoreSystemUI(); + } catch (e) { + appLogger.w('Failed to restore system UI', error: e); + } + + try { + if (_isPhone) { + await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); + } else { + await SystemChrome.setPreferredOrientations([ + DeviceOrientation.portraitUp, + DeviceOrientation.portraitDown, + DeviceOrientation.landscapeLeft, + DeviceOrientation.landscapeRight, + ]); + } + } catch (e) { + appLogger.w('Failed to restore orientation', error: e); + } + } + @override void dispose() { WidgetsBinding.instance.removeObserver(this); @@ -1128,23 +1153,7 @@ class VideoPlayerScreenState extends State with WidgetsBindin // Restore system UI and orientation preferences (skip if navigating to another video) if (!_isReplacingWithVideo) { - OrientationHelper.restoreSystemUI(); - - // Restore orientation based on cached device type (no context needed) - try { - if (_isPhone) { - SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); - } else { - SystemChrome.setPreferredOrientations([ - DeviceOrientation.portraitUp, - DeviceOrientation.portraitDown, - DeviceOrientation.landscapeLeft, - DeviceOrientation.landscapeRight, - ]); - } - } catch (e) { - appLogger.w('Failed to restore orientation in dispose', error: e); - } + unawaited(_restoreSystemUiAndOrientation()); } Sentry.addBreadcrumb(Breadcrumb(message: 'Player dispose', category: 'player')); diff --git a/lib/utils/orientation_helper.dart b/lib/utils/orientation_helper.dart index 73ffe0b9..bde88029 100644 --- a/lib/utils/orientation_helper.dart +++ b/lib/utils/orientation_helper.dart @@ -33,10 +33,12 @@ class OrientationHelper { SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]); } - /// Restores edge-to-edge system UI mode. + /// Restores the app's default visible system UI mode. /// /// Should be called when exiting full-screen mode. - static void restoreSystemUI() { - SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); + static Future restoreSystemUI() async { + // Explicitly show both overlays first to clear any legacy immersive flags. + await SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values); + await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); } } diff --git a/test/utils/orientation_helper_test.dart b/test/utils/orientation_helper_test.dart new file mode 100644 index 00000000..fad6459a --- /dev/null +++ b/test/utils/orientation_helper_test.dart @@ -0,0 +1,32 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:plezy/utils/orientation_helper.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + test('restoreSystemUI explicitly shows overlays before edge-to-edge', () async { + final calls = []; + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler( + SystemChannels.platform, + (call) async { + calls.add(call); + return null; + }, + ); + addTearDown( + () => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler( + SystemChannels.platform, + null, + ), + ); + + await OrientationHelper.restoreSystemUI(); + + expect(calls, hasLength(2)); + expect(calls[0].method, 'SystemChrome.setEnabledSystemUIOverlays'); + expect(calls[0].arguments, ['SystemUiOverlay.top', 'SystemUiOverlay.bottom']); + expect(calls[1].method, 'SystemChrome.setEnabledSystemUIMode'); + expect(calls[1].arguments, 'SystemUiMode.edgeToEdge'); + }); +}