add device orientation detection for optimal landscape rotation
This commit is contained in:
parent
50c9bb2387
commit
487700f5b7
1 changed files with 33 additions and 5 deletions
|
|
@ -16,6 +16,7 @@ import 'package:frosty/widgets/live_indicator.dart';
|
|||
import 'package:frosty/widgets/section_header.dart';
|
||||
import 'package:frosty/widgets/uptime.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:native_device_orientation/native_device_orientation.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
|
|
@ -172,12 +173,39 @@ class VideoOverlay extends StatelessWidget {
|
|||
color: surfaceColor,
|
||||
shadows: _iconShadow,
|
||||
),
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
if (context.isPortrait) {
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.landscapeRight,
|
||||
]);
|
||||
// Detect physical device tilt to rotate to optimal orientation
|
||||
final physicalOrientation =
|
||||
await NativeDeviceOrientationCommunicator()
|
||||
.orientation(useSensor: true);
|
||||
|
||||
// Map native orientation to Flutter's DeviceOrientation
|
||||
// iOS: native landscapeLeft = notch left, needs swap to Flutter's landscapeRight
|
||||
// Android: direct mapping works correctly
|
||||
final needsSwap = Platform.isIOS;
|
||||
|
||||
if (physicalOrientation ==
|
||||
NativeDeviceOrientation.landscapeLeft) {
|
||||
SystemChrome.setPreferredOrientations([
|
||||
needsSwap
|
||||
? DeviceOrientation.landscapeRight
|
||||
: DeviceOrientation.landscapeLeft,
|
||||
]);
|
||||
} else if (physicalOrientation ==
|
||||
NativeDeviceOrientation.landscapeRight) {
|
||||
SystemChrome.setPreferredOrientations([
|
||||
needsSwap
|
||||
? DeviceOrientation.landscapeLeft
|
||||
: DeviceOrientation.landscapeRight,
|
||||
]);
|
||||
} else {
|
||||
// Not tilted to landscape yet, allow both
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.landscapeRight,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue