Files
plezy/lib/utils/orientation_helper.dart
T

45 lines
1.7 KiB
Dart

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) {
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);
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<void> 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);
}
}