import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'platform_detector.dart'; class OrientationHelper { /// Restores default orientation preferences based on device type. /// /// For phones: Locks to portrait-only (up and down) /// For tablets/desktop: Allows all orientations /// /// This should be called when leaving full-screen experiences like /// the video player to restore the app's default orientation behavior. static void restoreDefaultOrientations(BuildContext context) { if (PlatformDetector.isAutomotive()) return; final isPhone = PlatformDetector.isPhone(context); if (isPhone) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); } else { SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, DeviceOrientation.portraitDown, DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight, ]); } } /// Sets orientation to landscape-only mode. /// /// Used by the video player to force landscape orientation during playback. static void setLandscapeOrientation() { SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky); if (PlatformDetector.isAutomotive()) return; SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]); } /// Restores the app's default visible system UI mode. /// /// Should be called when exiting full-screen mode. 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); } }